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

defaultModule :string

Source:

The package authorized to provide default language configurations

Type:
  • string

lang :string

Source:

The target language for localization

Type:
  • string

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
{
  "MYMODULE.GREETING": "Hello {name}, this is my module!"
}
game.i18n.format("MYMODULE.GREETING", {name: "Andrew"}); // Hello Andrew, this is my module!
Parameters:
Name Type Description
stringId string

The string ID to translate

data Object

Provided input data

Returns:

The translated and formatted string

Type
string

has(stringId, fallbackopt) → {boolean}

Source:

Return whether a certain string has a known translation defined.

Parameters:
Name Type Attributes Default Description
stringId string

The string key being translated

fallback boolean <optional>
true

Allow fallback translations to count?

Returns:
Type
boolean

(async) initialize() → {Promise.<void>}

Source:

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

Returns:

A Promise which resolves once languages are initialized

Type
Promise.<void>

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

Example
{
  "MYMODULE.MYSTRING": "Hello, this is my module!"
}
game.i18n.localize("MYMODULE.MYSTRING"); // Hello, this is my module!
Parameters:
Name Type Description
stringId String

The string ID to translate

Returns:

The translated string

Type
String

(async) setLanguage(lang) → {Promise.<void>}

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.<void>