API Reference
@univerjs
@univerjs/core
classes
Localeservice

@univerjs/core v0.4.2Docs


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

submodules/univer/packages/core/src/services/locale/locale.service.ts:36 (opens in a new tab)

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_disposedprotectedbooleanfalseDisposable._disposedsubmodules/univer/packages/core/src/shared/lifecycle.ts:93 (opens in a new tab)
currentLocale$readonlyObservable<LocaleType>undefined-submodules/univer/packages/core/src/services/locale/locale.service.ts:29 (opens in a new tab)
localeChanged$publicSubject<void>undefined-submodules/univer/packages/core/src/services/locale/locale.service.ts:34 (opens in a new tab)

Methods

dispose()

dispose(): void

Returns

void

Inherited from

Disposable.dispose

Defined in

submodules/univer/packages/core/src/shared/lifecycle.ts:106 (opens in a new tab)


disposeWithMe()

disposeWithMe(disposable): IDisposable

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

Disposable.disposeWithMe

Defined in

submodules/univer/packages/core/src/shared/lifecycle.ts:96 (opens in a new tab)


ensureNotDisposed()

protected ensureNotDisposed(): void

Returns

void

Inherited from

Disposable.ensureNotDisposed

Defined in

submodules/univer/packages/core/src/shared/lifecycle.ts:100 (opens in a new tab)


getCurrentLocale()

getCurrentLocale(): LocaleType

Returns

LocaleType

Defined in

submodules/univer/packages/core/src/services/locale/locale.service.ts:101 (opens in a new tab)


getLocales()

getLocales(): undefined | ILanguagePack

Returns

undefined | ILanguagePack

Defined in

submodules/univer/packages/core/src/services/locale/locale.service.ts:97 (opens in a new tab)


load()

load(locales): void

Load more locales after init.

Parameters

ParameterTypeDescription
localesILocalesLocale object

Returns

void

Defined in

submodules/univer/packages/core/src/services/locale/locale.service.ts:47 (opens in a new tab)


resolveKeyPath()

resolveKeyPath(obj, keys): null | LanguageValue

Parameters

ParameterType
objILanguagePack
keysstring[]

Returns

null | LanguageValue

Defined in

submodules/univer/packages/core/src/services/locale/locale.service.ts:105 (opens in a new tab)


setLocale()

setLocale(locale): void

Parameters

ParameterType
localeLocaleType

Returns

void

Defined in

submodules/univer/packages/core/src/services/locale/locale.service.ts:92 (opens in a new tab)


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

submodules/univer/packages/core/src/services/locale/locale.service.ts:76 (opens in a new tab)


Copyright © 2021-2024 DreamNum Co,Ltd. All Rights Reserved.