Interface: ILocaleService
molecule.ILocaleService
Implemented by
Methods
addLocales
▸ addLocales(locales
): void
Add multiple local languages
Parameters
Name | Type |
---|---|
locales | ILocale [] |
Returns
void
Defined in
getCurrentLocale
▸ getCurrentLocale(): undefined
| ILocale
Get the current locale language
Returns
undefined
| ILocale
Defined in
getDefaultLocale
▸ getDefaultLocale(): ILocale
Get the default locale
Returns
Defined in
getDefaultLocales
▸ getDefaultLocales(): ILocale
[]
Get the default locales;
Returns
ILocale
[]
Defined in
getLocale
▸ getLocale(id
): undefined
| ILocale
Get a locale language by the id
Parameters
Name | Type |
---|---|
id | string |
Returns
undefined
| ILocale
Defined in
getLocales
▸ getLocales(): ILocale
[]
Get All locale languages
Returns
ILocale
[]
Defined in
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
Name | Type |
---|---|
locales | ILocale [] |
localeId? | string |
Returns
void
Defined in
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
Name | Type | Description |
---|---|---|
sourceKey | string | The key value located in the source international text |
defaultValue | string | The default value to be used when not find the international text |
...args | string [] | If provided, it will used as the values to be replaced in the international text |
Returns
string
Defined in
onChange
▸ onChange(callback
): void
Listen to the local language changed event
Parameters
Name | Type |
---|---|
callback | (prev : ILocale , next : ILocale ) => void |
Returns
void
Defined in
removeLocale
▸ removeLocale(id
): undefined
| ILocale
Remove a locale language by the id
Parameters
Name | Type |
---|---|
id | string |
Returns
undefined
| ILocale
Defined in
reset
▸ reset(): void
Reset the LocaleService to the initial state
Returns
void
Defined in
setCurrentLocale
▸ setCurrentLocale(id
): boolean
Set the current locale language by id
Parameters
Name | Type |
---|---|
id | string |
Returns
boolean