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
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
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
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 current locale language,
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(listener
): void
Listen to the Component state update event
Parameters
Name | Type |
---|---|
listener | (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(listener?
): void
Remove the Component update event listening, default is remove all, also you can remove one by pass the listener
Parameters
Name | Type |
---|---|
listener? | Function |
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
, listener
): void
Subscribe the service event
Parameters
Name | Type | Description |
---|---|---|
name | string | string [] | Event name |
listener | Function | Listener function |
Returns
void
Inherited from
Defined in
transformLocaleData
▸ Private
transformLocaleData(locale
): ILocale
Parameters
Name | Type |
---|---|
locale | ILocale |
Returns
Defined in
unsubscribe
▸ unsubscribe(name
, listener?
): void
Unsubscribe the specific event and the listener function
Parameters
Name | Type | Description |
---|---|---|
name | any | The event name |
listener? | Function | optional, it unsubscribes events via name if not pass the listener function |
Returns
void