Dynamic messages with gettext (AngularJS)

I have an application with a Django backend and AngularJS front-end. I use the angular -gettext plugin with Grunt to handle translations.

The thing is, sometimes I got dynamic strings from my backend through the API. For example, a MySQL error regarding foreign key constraints or duplicate key entries. How can I add these lines to a .pot file or a line without binding in general?

I tried to follow, but of course it cannot work:

 angular.module('app').factory('HttpInterceptor', ['$q', '$injector', '$rootScope', '$cookieStore', 'gettext', function ($q, $injector, $rootScope, $cookieStore, gettext) {

            responseError: function (rejection) {
                    gettext('static string'); //it works
                    gettext(rejection.data.error); //does not work
                    $rootScope.$emit('errorModal', rejection.data);
                }

                // Return the promise rejection.
                return $q.reject(rejection);
            }
        };
    }]);

})();

One solution I could think of would be to write each dynamic line into a JSON object. Send this json to the server and from there write a static file containing these lines so gettext can extract them.

What are you offering?

+4
1

angular -gettext , . , , .

, . , . , . , .

html translate. , .

-, , {{foo}} bar, foo. postTranslate :

angular
.module('app')
.filter('postTranslate', ['gettextCatalog', function (gettextCatalog) {
    return function (s) {
        return gettextCatalog.getString(s);
    };
}]);

, , , . , .

, , , . , , :)

+3

All Articles