跳到主要内容
版本:0.9.0-beta.2

Class: LocaleService

molecule.LocaleService

Hierarchy

Implements

Constructors

constructor

new LocaleService()

Overrides

Component.constructor

Defined in

src/i18n/localeService.ts:96

Properties

_current

Private _current: undefined | ILocale

Defined in

src/i18n/localeService.ts:94


_locales

Private _locales: Map<string, ILocale>

Defined in

src/i18n/localeService.ts:93


state

state: Object = {}

Overrides

Component.state

Defined in

src/i18n/localeService.ts:90


LOCALIZE_REPLACED_WORD

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

Defined in

src/i18n/localeService.ts:91

Methods

addLocales

addLocales(locales): void

Add multiple local languages

Parameters

NameType
localesILocale[]

Returns

void

Implementation of

ILocaleService.addLocales

Defined in

src/i18n/localeService.ts:191


count

count(name): number

Count the service event

Parameters

NameTypeDescription
namestringEvent name

Returns

number

Inherited from

Component.count

Defined in

src/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

src/common/event/eventBus.ts:20


forceUpdate

forceUpdate(): void

Force to update the Component

Returns

void

Inherited from

Component.forceUpdate

Defined in

src/react/component.ts:79


getCurrentLocale

getCurrentLocale(): undefined | ILocale

Get the current locale language

Returns

undefined | ILocale

Implementation of

ILocaleService.getCurrentLocale

Defined in

src/i18n/localeService.ts:136


getDefaultLocale

getDefaultLocale(): ILocale

Get the default locale

Returns

ILocale

Implementation of

ILocaleService.getDefaultLocale

Defined in

src/i18n/localeService.ts:110


getDefaultLocales

getDefaultLocales(): ILocale[]

Get the default locales;

Returns

ILocale[]

Implementation of

ILocaleService.getDefaultLocales

Defined in

src/i18n/localeService.ts:114


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

src/i18n/localeService.ts:143


getLocales

getLocales(): ILocale[]

Get All locale languages

Returns

ILocale[]

Implementation of

ILocaleService.getLocales

Defined in

src/i18n/localeService.ts:118


getState

getState(): any

Get the Component state

Returns

any

Inherited from

Component.getState

Defined in

src/react/component.ts:83


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

Implementation of

ILocaleService.initialize

Defined in

src/i18n/localeService.ts:122


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

src/i18n/localeService.ts:207


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

src/i18n/localeService.ts:203


onUpdateState

onUpdateState(callback): void

Listen to the Component state update event

Parameters

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

Returns

void

Inherited from

Component.onUpdateState

Defined in

src/react/component.ts:71


removeLocale

removeLocale(id): undefined | ILocale

Remove a locale language by the id

Parameters

NameType
idstring

Returns

undefined | ILocale

Implementation of

ILocaleService.removeLocale

Defined in

src/i18n/localeService.ts:148


removeOnUpdateState

removeOnUpdateState(): void

Remove the Component update event listening

Returns

void

Inherited from

Component.removeOnUpdateState

Defined in

src/react/component.ts:75


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

src/react/component.ts:67


reset

reset(): void

Reset the LocaleService to the initial state

Returns

void

Implementation of

ILocaleService.reset

Defined in

src/i18n/localeService.ts:104


setCurrentLocale

setCurrentLocale(id): boolean

Set the current locale language by id

Parameters

NameType
idstring

Returns

boolean

Implementation of

ILocaleService.setCurrentLocale

Defined in

src/i18n/localeService.ts:160


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

src/react/component.ts:54


subscribe

subscribe(name, callback): void

Subscribe the service event

Parameters

NameTypeDescription
namestring | string[]Event name
callbackFunctionCallback function

Returns

void

Inherited from

Component.subscribe

Defined in

src/common/event/eventBus.ts:11


transformLocaleData

Private transformLocaleData(locale): ILocale

Parameters

NameType
localeILocale

Returns

ILocale

Defined in

src/i18n/localeService.ts:172


unsubscribe

unsubscribe(name): void

Unsubscribe the specific event

Parameters

NameTypeDescription
nameanyThe event name

Returns

void

Inherited from

Component.unsubscribe

Defined in

src/common/event/eventBus.ts:37