PolymerElements / app-localize-behavior

Polymer behaviour to help internationalize your application
48 stars 55 forks source link

Little answer #76

Open Gromov-Roman opened 7 years ago

Gromov-Roman commented 7 years ago

Good day!

How can I announce language and json files in one main html, and use just {{locale('something')}} or some any function in all my html files?

Many thanks for your attention!

hyyan commented 7 years ago

@kaycebasques It is already explained in the README file


<dom-module id="x-app">
   <template>
    <div>{{localize('hello', 'name', 'Batman')}}</div>
   </template>
   <script>
      Polymer({
        is: "x-app",

        behaviors: [
          Polymer.AppLocalizeBehavior
        ],

        properties: {
          language: {
            value: 'en'
          },
          resources: {
            value: function() {
              return {
                'en': { 'hello': 'My name is {name}.' },
                'fr': { 'hello': 'Je m\'apelle {name}.' }
              }
          }
        }
      });
   &lt;/script>
</dom-module>
Gromov-Roman commented 7 years ago

It is for one file, I must use

behaviors: [ Polymer.AppLocalizeBehavior ],
properties: {
   language: {  value: 'en'  },
   resources: {
      value: function() {
         return {
           'en': { 'hello': 'My name is {name}.' },
           'fr': { 'hello': 'Je m\'apelle {name}.' }
         }
     }
  }
}

in any file?