Skip to content
Marcus Krejpowicz edited this page Oct 30, 2013 · 1 revision

The I18n component

rappidjs comes with an I18n component that helps you to translate strings and formate dates and numbers. The I18n core component is defined in js/core/I18n.js.

Integrating I18n

The I18n component can be integrated with one line of code. Over the cid you can register the component in the scope of your application. If you want to share I18n over all components you can inject it. (See Injection) After the component is registered with the cid it can be used like a function binding. The example shows the basic concept.

<app:SampleAppClass xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:js="js.core">  
  
  <js:I18n cid="i18n" path="app/locale" locale="de_DE" loadMomentJs="false"/>
  <div>
     {i18n.t('hello','Bob')} <!-- translates 'Hallo %0!' -->
  </div>
</app:SampleAppClass>

The translate method t tries to find the translation of 'hello'. The second parameter ('Bob') is a placeholder value for the translation. So if the translation is 'Hallo %0!' the %0 will be replaced by 'Bob'.

How the I18n component works

When the I18n component gets initialized it looks in the defined path for the defined locale and tries to load the language file. In the case above it looks for app/local/de_DE.json. In this JSON file all translations should be defined.

Clone this wiki locally