angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Custom Annotations & Lazy Loading Languages

Open votemike opened this issue 9 years ago • 2 comments

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.

votemike avatar Dec 01 '15 15:12 votemike

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();
    }
  };
}]);

crisbeto avatar Jan 24 '16 09:01 crisbeto

Good little nugget here. Thanks @crisbeto for the feature and the support.

mattbrunetti avatar Mar 28 '17 16:03 mattbrunetti