I18N
Class for accessing internationalization (i18n) features.
Allows “detecting language change”, “setting the current language” or translating “individual terms”.
Internationalization works with terms, a string type keyword that is linked to a different text for each language.
Internally, string parameters for text and js components are automatically swapped during language change, given they are linked to a term. If manual text swapping is desired, translate can be used to retrieve the current translation for any term.
You can also use the onLanguageChanged to manually update text when a language is changed to for example update a number in a string.
- I18N
- .constructor(engine) ⇒ I18N
- .onLanguageChanged: Emitter<[number, number]>
- .currentIndex
- .engine
- .language
- .previousIndex
- .languageCode(index) ⇒ null | string
- .languageCount() ⇒ number
- .languageIndex(code) ⇒ number
- .languageName(index) ⇒ null | string
- .setLanguage(code) ⇒ Promise<number>
- .translate(term) ⇒ null | string
.constructor(engine: WonderlandEngine) ⇒ I18N
Constructor
Param | Type | Description |
---|---|---|
engine | WonderlandEngine |
.onLanguageChanged: Emitter<[number, number]>
Emitter for language change events.
First parameter to a listener is the old language index, second parameter is the new language index.
Usage from a within a component:
.currentIndex: number
Get the current language index.
This method is more efficient than its equivalent:
1const index = i18n.languageIndex(i18n.language);
.engine: WonderlandEngine
Hosting engine instance.
.language: null | string
Get current language code.
.language
Set current language and apply translations to linked text parameters.
Note: This is equivalent to setLanguage.
.previousIndex: number
Previous language index.
.languageCode(index: number) ⇒ null | string
Get a language code.
Param | Type | Description |
---|---|---|
index | number | Index of the language to get the code from |
.languageCount() ⇒ number
Get the number of languages in the project.
.languageIndex(code: string) ⇒ number
Get a language code.
Param | Type | Description |
---|---|---|
code | string |
.languageName(index: number) ⇒ null | string
Get a language name.
Param | Type | Description |
---|---|---|
index | number | Index of the language to get the name from |
.setLanguage(code: null | string) ⇒ Promise<number>
Set current language and apply translations to linked text parameters.
Returns: A promise that resolves with the current index code when the language is loaded.
Param | Type | Description |
---|---|---|
code | null | string | The language code. |
.translate(term: string) ⇒ null | string
Get translated string for a term for the currently loaded language.
Param | Type | Description |
---|---|---|
term | string | Term to translate |