Class: LocaleService
molecule.LocaleService
Hierarchy
↳
LocaleService
Implements
Constructors
constructor
• new LocaleService()
Overrides
Defined in
Properties
_current
• Private
_current: undefined
| ILocale
Defined in
_locales
• Private
_locales: Map
<string
, ILocale
>
Defined in
state
• state: Object
= {}
Overrides
Defined in
LOCALIZE_REPLACED_WORD
▪ Static
Private
LOCALIZE_REPLACED_WORD: string
= '${i}'
Defined in
Methods
addLocales
▸ addLocales(locales
): void
Add multiple local languages
Parameters
Name | Type |
---|---|
locales | ILocale [] |
Returns
void
Implementation of
Defined in
count
▸ count(name
): number
Count the service event
Parameters
Name | Type | Description |
---|---|---|
name | string | Event name |
Returns
number
Inherited from
Defined in
src/common/event/eventBus.ts:28
emit
▸ emit(name
, ...args
): void
Emit the service event
Parameters
Name | Type | Description |
---|---|---|
name | string | Event name |
...args | any | Arguments |
Returns
void
Inherited from
Defined in
src/common/event/eventBus.ts:20
forceUpdate
▸ forceUpdate(): void
Force to update the Component
Returns
void
Inherited from
Defined in
getCurrentLocale
▸ getCurrentLocale(): undefined
| ILocale
Get the current locale language
Returns
undefined
| ILocale
Implementation of
ILocaleService.getCurrentLocale
Defined in
getDefaultLocale
▸ getDefaultLocale(): ILocale
Get the default locale
Returns
Implementation of
ILocaleService.getDefaultLocale
Defined in
getDefaultLocales
▸ getDefaultLocales(): ILocale
[]
Get the default locales;
Returns
ILocale
[]
Implementation of
ILocaleService.getDefaultLocales
Defined in
getLocale
▸ getLocale(id
): undefined
| ILocale
Get a locale language by the id
Parameters
Name | Type |
---|---|
id | null | string |
Returns
undefined
| ILocale
Implementation of
Defined in
getLocales
▸ getLocales(): ILocale
[]
Get All locale languages
Returns
ILocale
[]
Implementation of
Defined in
getState
▸ getState(): any
Get the Component state
Returns
any
Inherited from
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
Implementation of
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 | Default value |
---|---|---|
sourceKey | string | undefined |
defaultValue | string | '' |
...args | string [] | undefined |
Returns
string
Implementation of
Defined in
onChange
▸ onChange(callback
): void
Listen to the local language changed event
Parameters
Name | Type |
---|---|
callback | (prev : ILocale , next : ILocale ) => void |
Returns
void
Implementation of
Defined in
onUpdateState
▸ onUpdateState(callback
): void
Listen to the Component state update event
Parameters
Name | Type |
---|---|
callback | (prevState : any , nextState : any ) => void |
Returns
void
Inherited from
Defined in
removeLocale
▸ removeLocale(id
): undefined
| ILocale
Remove a locale language by the id
Parameters
Name | Type |
---|---|
id | string |
Returns
undefined
| ILocale
Implementation of
Defined in
removeOnUpdateState
▸ removeOnUpdateState(): void
Remove the Component update event listening
Returns
void
Inherited from
Defined in
render
▸ render(nextState?
): void
Initiative notify the component to render the view by the state
Parameters
Name | Type |
---|---|
nextState? | any |
Returns
void
Inherited from
Defined in
reset
▸ reset(): void
Reset the LocaleService to the initial state
Returns
void
Implementation of
Defined in
setCurrentLocale
▸ setCurrentLocale(id
): boolean
Set the current locale language by id
Parameters
Name | Type |
---|---|
id | string |
Returns
boolean
Implementation of
ILocaleService.setCurrentLocale
Defined in
setState
▸ setState(values
, callback?
): void
Set the state values, and notify the view component to re render
Parameters
Name | Type | Description |
---|---|---|
values | Partial <any > | update target state values |
callback? | (prevState : any , nextState : any ) => void | - |
Returns
void
Inherited from
Defined in
subscribe
▸ subscribe(name
, callback
): void
Subscribe the service event
Parameters
Name | Type | Description |
---|---|---|
name | string | string [] | Event name |
callback | Function | Callback function |
Returns
void
Inherited from
Defined in
src/common/event/eventBus.ts:11
transformLocaleData
▸ Private
transformLocaleData(locale
): ILocale
Parameters
Name | Type |
---|---|
locale | ILocale |
Returns
Defined in
unsubscribe
▸ unsubscribe(name
): void
Unsubscribe the specific event
Parameters
Name | Type | Description |
---|---|---|
name | any | The event name |
Returns
void