Good Practice With Angular Translate

I am trying to use angular translate and had a best practice question. Your best bet is to use a key for a line like this:

app.config(function($translateProvider) {
  $translateProvider.translations('en', {
    HEADLINE: 'Hello there, This is my awesome app!',
    INTRO_TEXT: 'And it has i18n support!'
  });
});

      

and

<h2>{{ 'HEADLINE' | translate }}</h2>
<p>{{ 'INTRO_TEXT' | translate }}</p>

      

as opposed to something like:

<h2 ng-bind="'Hello there, This is my awesome app!' | translate"></h2>

      

and if so why does one method work best over another? Is the key being used for multilingual support?

+3


source to share


1 answer


I prefer short keys instead of English text as the key .. This will blow up your HTML and your JS config file .. when you use short keys you can also insert keys for example.

{
  user: {
   name: 'Name', 
   email: 'E-Mail'
  }
} 

      

and use it in this HTML



<p translate="user.name"></p>

      

and you have to use directive instead of filter .. that's why: https://github.com/angular-translate/angular-translate/wiki/Getting-Started#using-translate-directive

+6


source







All Articles