@univerjscoreclassesLocaleservice

@univerjs/core v0.5.0-beta.1Docs


Class: LocaleService

This service provides i18n and timezone / location features to other modules.

Extends

Constructors

new LocaleService()

new LocaleService(): LocaleService

Returns

LocaleService

Overrides

Disposable.constructor

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:36

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_disposedprotectedbooleanfalseDisposable._disposedpackages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:93
currentLocale$readonlyObservable<LocaleType>undefined-packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:29
localeChanged$publicSubject<void>undefined-packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:34

Methods

dispose()

dispose(): void

Returns

void

Inherited from

Disposable.dispose

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:106


disposeWithMe()

disposeWithMe(disposable): IDisposable

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

Disposable.disposeWithMe

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:96


ensureNotDisposed()

protected ensureNotDisposed(): void

Returns

void

Inherited from

Disposable.ensureNotDisposed

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:100


getCurrentLocale()

getCurrentLocale(): LocaleType

Returns

LocaleType

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:101


getLocales()

getLocales(): undefined | ILanguagePack

Returns

undefined | ILanguagePack

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:97


load()

load(locales): void

Load more locales after init.

Parameters

ParameterTypeDescription
localesILocalesLocale object

Returns

void

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:47


resolveKeyPath()

resolveKeyPath(obj, keys): null | LanguageValue

Parameters

ParameterType
objILanguagePack
keysstring[]

Returns

null | LanguageValue

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:105


setLocale()

setLocale(locale): void

Parameters

ParameterType
localeLocaleType

Returns

void

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:92


t()

t(key, ...args): string

Translate a key to the current locale

Parameters

ParameterTypeDescription
keystringthe key to translate
argsstring[]optional arguments to replace in the translated string

Returns

string

the translated string

Examples

const locales = {
  [LocaleType.EN_US]: {
    foo: {
      bar: 'Hello'
   }
}
t('foo.bar') => 'Hello'
const locales = {
  [LocaleType.EN_US]: {
    foo: {
      bar: 'Hello {0}'
   }
}
t('foo.bar', 'World') => 'Hello World'

Defined in

packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:76