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​

m2c2kit/packages/core/src/I18n.ts:54

Properties​

baseLocale​

baseLocale: string = "en-US"

Defined in​

m2c2kit/packages/core/src/I18n.ts:44


fallbackLocale​

fallbackLocale: string = "en-US"

Defined in​

m2c2kit/packages/core/src/I18n.ts:43


game​

game: Game

Defined in​

m2c2kit/packages/core/src/I18n.ts:46


locale​

locale: string = ""

Defined in​

m2c2kit/packages/core/src/I18n.ts:42


missingLocalizationColor​

missingLocalizationColor: undefined | RgbaColor

Defined in​

m2c2kit/packages/core/src/I18n.ts:45

Accessors​

translation​

Get Signature​

get translation(): Translation

Returns​

Translation

Set Signature​

set translation(value): void

Parameters​

• value: Translation

Returns​

void

Defined in​

m2c2kit/packages/core/src/I18n.ts:628

Methods​

getTextLocalization()​

getTextLocalization(key, interpolation?): TextLocalizationResult

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

Parameters​

• key: string

Translation key

• interpolation?: StringInterpolationMap

Interpolation keys and values to replace string interpolation placeholders in the translated text

Returns​

TextLocalizationResult

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

Defined in​

m2c2kit/packages/core/src/I18n.ts:187


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​

m2c2kit/packages/core/src/I18n.ts:86


switchToLocale()​

switchToLocale(locale): void

Parameters​

• locale: string

Returns​

void

Defined in​

m2c2kit/packages/core/src/I18n.ts:158


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​

m2c2kit/packages/core/src/I18n.ts:468


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​

m2c2kit/packages/core/src/I18n.ts:509


makeLocalizationParameters()​

static makeLocalizationParameters(): GameParameters

Returns​

GameParameters

Defined in​

m2c2kit/packages/core/src/I18n.ts:680