Skip to main content

Class: I18n

Constructors

new I18n()

new I18n(game, options): I18n

The I18n class localizes text and images.

Parameters

game: Game

game instance

options: LocalizationOptions

LocalizationOptions

Returns

I18n

Defined in

I18n.ts:39

Properties

baseLocale

baseLocale: string = "en-US"

Defined in

I18n.ts:29


fallbackLocale

fallbackLocale: string = "en-US"

Defined in

I18n.ts:28


game

game: Game

Defined in

I18n.ts:31


locale

locale: string = ""

Defined in

I18n.ts:27


missingLocalizationColor

missingLocalizationColor: undefined | RgbaColor

Defined in

I18n.ts:30

Accessors

translation

Get Signature

get translation(): Translation

Returns

Translation

Set Signature

set translation(value): void

Parameters

value: Translation

Returns

void

Defined in

I18n.ts:371

Methods

getTextLocalization()

getTextLocalization(key, interpolation?): TextLocalizationResult

Parameters

key: string

Translation key

interpolation?: StringInterpolationMap

Interpolation keys and values to replace placeholders in the translated text

Returns

TextLocalizationResult

a TextLocalizationResult object with the localized text, font information, and whether the translation is a fallback.

Defined in

I18n.ts:170


initialize()

initialize(): Promise<void>

Initializes the I18n instance and sets the initial locale.

Returns

Promise<void>

Remarks

If the game instance has been configured to use a data store, the previously used locale and fallback locale will be retrieved from the data store if they have been previously set.

Defined in

I18n.ts:71


switchToLocale()

switchToLocale(locale): void

Parameters

locale: string

Returns

void

Defined in

I18n.ts:143


t()

t(key, options?): undefined | string

Returns the translation text for the given key in the current locale.

Parameters

key: string

key to look up in the translation

options?: TranslationOptions

TranslationOptions, such as interpolation keys/values and whether to translate using the fallback locale

Returns

undefined | string

the translation text for the key in the current locale, or undefined if the key is not found

Remarks

Optional interpolation keys and values can be provided to replace placeholders in the translated text. Placeholders are denoted by double curly braces.

Example

const translation: Translation = {
"en-US": {
"GREETING": "Hello, {{name}}."
}
}
...
i18n.t("GREETING", { name: "World" }); // returns "Hello, World."

Defined in

I18n.ts:224


tf()

tf(key, options?): undefined | TextAndFont

Returns the translation text and font information for the given key in the current locale.

Parameters

key: string

key to look up in the translation

options?: TranslationOptions

TranslationOptions, such as interpolation keys/values and whether to translate using the fallback locale

Returns

undefined | TextAndFont

the translation text and font information for the key in the current locale, or undefined if the key is not found

Remarks

Optional interpolation keys and values can be provided to replace placeholders in the translated text. Placeholders are denoted by double curly braces. See method () for interpolation example.

Defined in

I18n.ts:263


makeLocalizationParameters()

static makeLocalizationParameters(): GameParameters

Returns

GameParameters

Defined in

I18n.ts:423