Skip to main content
Version: 0.9.0-beta.2

Interface: ILocaleService

molecule.ILocaleService

Implemented by

Methods

addLocales

addLocales(locales): void

Add multiple local languages

Parameters

NameType
localesILocale[]

Returns

void

Defined in

src/i18n/localeService.ts:51


getCurrentLocale

getCurrentLocale(): undefined | ILocale

Get the current locale language

Returns

undefined | ILocale

Defined in

src/i18n/localeService.ts:29


getDefaultLocale

getDefaultLocale(): ILocale

Get the default locale

Returns

ILocale

Defined in

src/i18n/localeService.ts:42


getDefaultLocales

getDefaultLocales(): ILocale[]

Get the default locales;

Returns

ILocale[]

Defined in

src/i18n/localeService.ts:46


getLocale

getLocale(id): undefined | ILocale

Get a locale language by the id

Parameters

NameType
idstring

Returns

undefined | ILocale

Defined in

src/i18n/localeService.ts:38


getLocales

getLocales(): ILocale[]

Get All locale languages

Returns

ILocale[]

Defined in

src/i18n/localeService.ts:33


initialize

initialize(locales, localeId?): void

Initialize the locales data, and the default current locale language, this method first uses the cached locale in localStorage, then use the localeId argument, if both the values are null, finally apply the built-in BuiltInZhCN

Parameters

NameType
localesILocale[]
localeId?string

Returns

void

Defined in

src/i18n/localeService.ts:20


localize

localize(sourceKey, defaultValue, ...args): string

Returns the international text located by source key,or the default value if it is not find For examples:

localize('id', 'default value'); // hello ${i}, ${i}
localize('id', 'default value', 'world'); // hello world, ${i}
localize('id', 'default value', 'world', 'molecule'); // hello world, molecule

Parameters

NameTypeDescription
sourceKeystringThe key value located in the source international text
defaultValuestringThe default value to be used when not find the international text
...argsstring[]If provided, it will used as the values to be replaced in the international text

Returns

string

Defined in

src/i18n/localeService.ts:70


onChange

onChange(callback): void

Listen to the local language changed event

Parameters

NameType
callback(prev: ILocale, next: ILocale) => void

Returns

void

Defined in

src/i18n/localeService.ts:79


removeLocale

removeLocale(id): undefined | ILocale

Remove a locale language by the id

Parameters

NameType
idstring

Returns

undefined | ILocale

Defined in

src/i18n/localeService.ts:56


reset

reset(): void

Reset the LocaleService to the initial state

Returns

void

Defined in

src/i18n/localeService.ts:83


setCurrentLocale

setCurrentLocale(id): boolean

Set the current locale language by id

Parameters

NameType
idstring

Returns

boolean

Defined in

src/i18n/localeService.ts:25