Internationalization in JavaScript

Context Specific Translation

Some strings in different contexts can require different translations. If you need to provide a context specific translation, the msgid must contain both, the translation string and the context in the form of “<translation string>_<context>”. For example, if the translation string is “Please wait” and the context is “Submit”, the respective msgid must be “Please wait_Submit”. A context can be created by the system for predefined translations. A package developer can create custom contexts as well.

Predefined Translation

Some default strings used in APS JS SDK widgets have predefined translations into the following languages:

  • de_DE - German

  • es_ES - Spanish

  • fr_FR - French

  • ja_JP - Japanese

  • nl_NL - Dutch

  • pt_BR - Brazilian Portuguese

  • ru_RU - Russian

The following strings have predefined translations:

WIDGET

TRANSLATION STRING

CONTEXT

DEFAULT VALUE

aps/Button

Please wait

apsButton

Please wait

aps/DateTextBox

Select date

apsCalendar

Select date

aps/Grid

No item(s) found

apsGrid

No item(s) found

aps/Grid

Number of entries per page:

apsGrid

Number of entries per page:

aps/Grid

item(s) total

apsGrid

item(s) tota

aps/Grid

Search

apsGrid

Search

aps/Grid

Reset Search

apsGrid

Reset Search

aps/Grid

First

apsGrid

First

aps/Grid

Last

apsGrid

Last

aps/Grid

All

apsGrid

All

aps/Grid

Pages

apsGrid

Pages

aps/ListSwitcher

Settings

apsListSwitcher

Settings

aps/ListSwitcher

Sorting:

apsListSwitcher

Sorting:

aps/ListSwitcher

In ascending order: A to Z

apsListSwitcher

In ascending order: A to Z

aps/ListSwitcher

In descending order: Z to A

apsListSwitcher

In descending order: Z to A

aps/ListSwitcher

List View Mode:

apsListSwitcher

List View Mode:

aps/ListSwitcher

Active List

apsListSwitcher

Active List

aps/ListSwitcher

Classic List

apsListSwitcher

Classic List

aps/Password

Reset password

apsPassword

Reset password

aps/Password

Hide password

apsPassword

Hide password

aps/Password

Show password

apsPassword

Show password

aps/Password

Password does not match

apsPassword

Password does not match

aps/Password

Reset

apsPassword

Reset

aps/Password

The value entered is not valid.

apsPassword

The value entered is not valid.

aps/Password

This value is required.

apsPassword

This value is required.

aps/ProgressBar

completed

apsProgressBar

completed

aps/Slider

This value is out of range.

apsSlider

This value is out of range.

aps/Slider

The value entered is not valid.

apsSlider

The value entered is not valid.

aps/Slider

This value is required.

apsSlider

This value is required.

aps/Switch

ON

apsSwitch

ON

aps/Switch

OFF

apsSwitch

OFF

aps/TextBox

Not valid value

apsTextBox

Not valid value

aps/TextBox

The value entered is not valid.

apsTextBox

The value entered is not valid.

aps/TextBox

This value is required.

apsTextBox

This value is required.

aps/TextBox

All symbols required.

apsTextBox

All symbols required.

aps/ToolbarButton

Please wait

apsToolbarButton

Please wait

aps/ToolsItem

Please wait

apsToolsItem

Please wait

Note

The predefined translations are not present in po files. If you need to substitute a predefined translation with your own custom string, you need to manually create the respective msgid and msgstr pair in the proper po file. The msgid string must include the respective context as presented in the above table.

Custom Translation

Translation Hook

The aps msgmake command extracts localization data from JavaScript code in *.html and *.js files used for building UI views. The _() function is a hook that makes a string available for translation. For example, _("string to translate") makes the aps msgmake command create the msgid “string to translate” and “msgstr” pair in the PO files.

The aps/i18n module redefines the window._() function.

Translation of Plurals

In general, a string may contain mapped parameters that should not be translated. The mapped parameters must be enclosed by a pair of underscores “__”. In the following example, the msgKey string contains parameters whose values must be found in the paramObjects mapping string.

_(msgKey, paramObjects)

The _() function is used to localize the string @msgKey. For example, @msgKey is actually a string “Found __itemsCount__ item(s)”. This string contains the itemsCount parameter, wrapped by a pair of underscores. The parameter is defined by the mapping string, for example, {“itemsCount”:counter}.

So, if aps msgmake meets the following code when parsing a JavaScript code:

_("Found __itemsCount__ item(s)", {"itemsCount":itemsCount})

it automatically generates the following pair of records in the PO file:

msgid "Found __itemsCount__ item(s)"
msgstr ""

A translator can manually translate the message in the following way, for example, into Russian:

msgid "Found __itemsCount__ item(s)"
msgstr "Найдено __itemsCound__ элемент(ов)"

Custom Context

If a string translation is context dependent, specify a custom context as in the following example:

title: _("Context specific title", { context: "myOwnContext" })

For each context with the same string, the APS build utility will create a separate msgid and msgstr pair. For the above example, it will be:

msgid "Context specific title_myOwnContext"
msgstr ""

If the same string is used without a context property, a respective msgid will be created without the context property. In the process of building a widget on the client side, the context specific translation takes precedence over the context-less translation.