Skip to main content
Version: 1.x

Class: LocaleService

molecule.LocaleService

Hierarchy

Implements

Constructors

constructor

new LocaleService()

Overrides

Component.constructor

Defined in

i18n/localeService.ts:83

Properties

_current

Private _current: undefined | ILocale

Defined in

i18n/localeService.ts:81


_locales

Private _locales: Map<string, ILocale>

Defined in

i18n/localeService.ts:80


state

state: Object = {}

Overrides

Component.state

Defined in

i18n/localeService.ts:77


LOCALIZE_REPLACED_WORD

Static Private LOCALIZE_REPLACED_WORD: string = '${i}'

Defined in

i18n/localeService.ts:78

Methods

addLocales

addLocales(locales): void

Add multiple local languages

Parameters

NameType
localesILocale[]

Returns

void

Implementation of

ILocaleService.addLocales

Defined in

i18n/localeService.ts:164


count

count(name): number

Count the service event

Parameters

NameTypeDescription
namestringEvent name

Returns

number

Inherited from

Component.count

Defined in

common/event/eventBus.ts:28


emit

emit(name, ...args): void

Emit the service event

Parameters

NameTypeDescription
namestringEvent name
...argsanyArguments

Returns

void

Inherited from

Component.emit

Defined in

common/event/eventBus.ts:20


forceUpdate

forceUpdate(): void

Force to update the Component

Returns

void

Inherited from

Component.forceUpdate

Defined in

react/component.ts:81


getCurrentLocale

getCurrentLocale(): undefined | ILocale

Get the current locale language

Returns

undefined | ILocale

Implementation of

ILocaleService.getCurrentLocale

Defined in

i18n/localeService.ts:106


getLocale

getLocale(id): undefined | ILocale

Get a locale language by the id

Parameters

NameType
idnull | string

Returns

undefined | ILocale

Implementation of

ILocaleService.getLocale

Defined in

i18n/localeService.ts:110


getLocales

getLocales(): ILocale[]

Get All locale languages

Returns

ILocale[]

Implementation of

ILocaleService.getLocales

Defined in

i18n/localeService.ts:93


getState

getState(): any

Get the Component state

Returns

any

Inherited from

Component.getState

Defined in

react/component.ts:85


initialize

initialize(locales, localeId): void

Initialize the locales data, and the current locale language,

Parameters

NameType
localesILocale[]
localeIdstring

Returns

void

Implementation of

ILocaleService.initialize

Defined in

i18n/localeService.ts:97


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

NameTypeDefault value
sourceKeystringundefined
defaultValuestring''
...argsstring[]undefined

Returns

string

Implementation of

ILocaleService.localize

Defined in

i18n/localeService.ts:180


onChange

onChange(callback): void

Listen to the local language changed event

Parameters

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

Returns

void

Implementation of

ILocaleService.onChange

Defined in

i18n/localeService.ts:176


onUpdateState

onUpdateState(listener): void

Listen to the Component state update event

Parameters

NameType
listener(prevState: any, nextState: any) => void

Returns

void

Inherited from

Component.onUpdateState

Defined in

react/component.ts:73


removeLocale

removeLocale(id): undefined | ILocale

Remove a locale language by the id

Parameters

NameType
idstring

Returns

undefined | ILocale

Implementation of

ILocaleService.removeLocale

Defined in

i18n/localeService.ts:115


removeOnUpdateState

removeOnUpdateState(listener?): void

Remove the Component update event listening, default is remove all, also you can remove one by pass the listener

Parameters

NameType
listener?Function

Returns

void

Inherited from

Component.removeOnUpdateState

Defined in

react/component.ts:77


render

render(nextState?): void

Initiative notify the component to render the view by the state

Parameters

NameType
nextState?any

Returns

void

Inherited from

Component.render

Defined in

react/component.ts:69


reset

reset(): void

Reset the LocaleService to the initial state

Returns

void

Implementation of

ILocaleService.reset

Defined in

i18n/localeService.ts:87


setCurrentLocale

setCurrentLocale(id): boolean

Set the current locale language by id

Parameters

NameType
idstring

Returns

boolean

Implementation of

ILocaleService.setCurrentLocale

Defined in

i18n/localeService.ts:133


setState

setState(values, callback?): void

Set the state values, and notify the view component to re render

Parameters

NameTypeDescription
valuesPartial<any>update target state values
callback?(prevState: any, nextState: any) => void-

Returns

void

Inherited from

Component.setState

Defined in

react/component.ts:56


subscribe

subscribe(name, listener): void

Subscribe the service event

Parameters

NameTypeDescription
namestring | string[]Event name
listenerFunctionListener function

Returns

void

Inherited from

Component.subscribe

Defined in

common/event/eventBus.ts:11


transformLocaleData

Private transformLocaleData(locale): ILocale

Parameters

NameType
localeILocale

Returns

ILocale

Defined in

i18n/localeService.ts:145


unsubscribe

unsubscribe(name, listener?): void

Unsubscribe the specific event and the listener function

Parameters

NameTypeDescription
nameanyThe event name
listener?Functionoptional, it unsubscribes events via name if not pass the listener function

Returns

void

Inherited from

Component.unsubscribe

Defined in

common/event/eventBus.ts:37