Internationalization functions.
Example
var i18nLib = require('/lib/xp/i18n');
Methods
(static) getPhrases(locale, bundles) → {object}
This function returns all phrases for the given locale and bundles.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | Array.<string> | A string-representation of a locale, or an array of locales in preferred order. |
bundles |
Array.<string> | List of bundle names. Bundle names are specified as paths, relative to the |
Returns:
An object of all phrases.
- Type
- object
Example
i18nLib.getPhrases('en', ['i18n/phrases'])
(static) getSupportedLocales(bundles) → {Array.<string>}
This function returns the list of supported locale codes for the specified bundles.
Parameters:
Name | Type | Description |
---|---|---|
bundles |
Array.<string> | List of bundle names. |
Returns:
A list of supported locale codes for the specified bundles.
- Type
- Array.<string>
(static) localize(params) → {string}
This function localizes a phrase.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object | JSON with the parameters. Properties
|
Returns:
The localized string.
- Type
- string
Examples
// Localizes a simple message.
var message1 = i18nLib.localize({
key: 'mymessage'
});
// Localizes a message with placeholders.
var message2 = i18nLib.localize({
key: 'mymessage_with_placeholder',
locale: "no",
values: ["John", "London"]
});