Translation and I18N

To allow your application to be translated an Internationalization is integrated in the App framework.

Defining the phrases

Language files need to be located in the src/locales folder with at least a en-US or en locale.

Each phrase is associated to a unique id which is used to retrieve it in the application:

hello_name: "Hello, {{name}}!"

You can organise phrases into structures.

welcome:
  back: "Welcome back"
  again: "Hello again"

When you do this, you refer to the phrase by the full ID, using dots to denote hierarchy, for example

<Phrase id="welcome.again" />

Using the phrases

To use a phrase in your code, use the i18n helper available from dpapp like this:

<p>{dpapp.i18n.t("hello_name", { name: "John" )}</p>

You can also use the shorter alias t :

<p>{dpapp.t("hello_name", { name: "John" )}</p>

Or finally you can use the Phrase component:

Plural

If your phrases need to handle counts you can add a plural version of a phrase:

Then the phrase will be automatically selected based on the count attribute value:

You can also include the {{count}} value in your phrase:

Languages with multiple plurals

This sample uses Arabic that has 5 plural forms beside the singular:

Which gets:

Last updated