angular-gettext
angular-gettext copied to clipboard
Custom Annotations & Lazy Loading Languages
Custom Annotations for placeholders as in the example don't seem to work when lazy loading languages.
It seems the language is not loaded before the string is translated. But also, strings translated through getString()
are not updated once a language has been loaded.
Hey, I'm the one that added the custom annotations. I believe this is because I tried to provide the simplest example of the use case. The whole point of custom annotations was to allow people to do their own translation directives, but that also means that you'd need to account for these types of scenarios yourself.
In this case, the example from the site would need to listen to the gettextLanguageChanged
event. It can be rewritten as:
angular.module('myModule').directive('placeholder', ['gettextCatalog', function(gettextCatalog){
return {
restrict: 'A',
link: function(scope, element, attrs){
var setTranslation = function(){
var translatedPlaceholder = gettextCatalog.getString(attrs.placeholder);
element.attr('placeholder', translatedPlaceholder);
};
scope.$on('gettextLanguageChanged', setTranslation);
setTranslation();
}
};
}]);
Good little nugget here. Thanks @crisbeto for the feature and the support.