@univerjscoreclassesLocaleservice

@univerjs/core v0.5.4


Class: LocaleService

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

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

Extends

Constructors

new LocaleService()

new LocaleService(): LocaleService

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

Returns

LocaleService

Overrides

Disposable.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_disposedprotectedbooleanfalseDisposable._disposedpackages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:96
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

Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:109

Returns

void

Inherited from

Disposable.dispose


disposeWithMe()

disposeWithMe(disposable): IDisposable

Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:99

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

Disposable.disposeWithMe


ensureNotDisposed()

protected ensureNotDisposed(): void

Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:103

Returns

void

Inherited from

Disposable.ensureNotDisposed


getCurrentLocale()

getCurrentLocale(): LocaleType

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

Returns

LocaleType


getLocales()

getLocales(): undefined | ILanguagePack

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

Returns

undefined | ILanguagePack


load()

load(locales): void

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

Load more locales after init.

Parameters

ParameterTypeDescription
localesILocalesLocale object

Returns

void


resolveKeyPath()

resolveKeyPath(obj, keys): null | LanguageValue

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

Parameters

ParameterType
objILanguagePack
keysstring[]

Returns

null | LanguageValue


setLocale()

setLocale(locale): void

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

Parameters

ParameterType
localeLocaleType

Returns

void


t()

t(key, ...args): string

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

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'