i18n

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 src/main/resources folder.

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
Name Type Attributes Description
key string

The property key.

locale string | Array.<string> <optional>

A string-representation of a locale, or an array of locales in preferred order. If the locale is not set, the site language is used.

values Array.<string> <optional>

Optional placeholder values.

bundles Array.<string> <optional>

Optional list of bundle names.

application string <optional>

Application key where to find resource bundles. Defaults to current application.

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"]
});