Localization

Localization

A helper class which assists with localization and string translation

Constructor

new Localization()

Source:

Members

_fallback :Object

Source:

Fallback translations if the target keys are not found

Type:
  • Object

lang :String

Source:

The target language for localization

Type:

translations :Object

Source:

The translation dictionary for the target language

Type:
  • Object

Methods

format(stringId, data) → {string}

Source:

Localize a string including variable formatting for input arguments. Provide a string ID which defines the localized template. Variables can be included in the template enclosed in braces and will be substituted using those named keys.

Example
const stringId = "MY_TEST_STRING"; // "Your name is {name}"
game.i18n.format("MY_TEST_STRING", {name: "Andrew"}); // Produces "Your name is Andrew"
Parameters:
Name Type Description
stringId string

The string ID to translate

data Object

Provided input data

Returns:

The translated and formatted string

Type
string

(async) initialize() → {Promise}

Source:

Initialize the Localization module Discover available language translations and apply the current language setting

Returns:
Type
Promise

localize(stringId) → {String}

Source:

Localize a string by drawing a translation from the available translations dictionary, if available If a translation is not available, the original string is returned

Parameters:
Name Type Description
stringId String

The string ID to translate

Returns:

The translated string

Type
String

(async) setLanguage(lang) → {Promise}

Source:

Set a language as the active translation source for the session

Parameters:
Name Type Description
lang string

A language string in CONFIG.supportedLanguages

Returns:

A Promise which resolves once the translations for the requested language are ready

Type
Promise