@univerjs/core v0.4.2 • Docs
Class: LocaleService
This service provides i18n and timezone / location features to other modules.
Extends
Constructors
new LocaleService()
new LocaleService(): LocaleService
Returns
Overrides
Defined in
submodules/univer/packages/core/src/services/locale/locale.service.ts:36 (opens in a new tab)
Properties
Property | Modifier | Type | Default value | Inherited from | Defined in |
---|---|---|---|---|---|
_disposed | protected | boolean | false | Disposable ._disposed | submodules/univer/packages/core/src/shared/lifecycle.ts:93 (opens in a new tab) |
currentLocale$ | readonly | Observable <LocaleType > | undefined | - | submodules/univer/packages/core/src/services/locale/locale.service.ts:29 (opens in a new tab) |
localeChanged$ | public | Subject <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
Defined in
submodules/univer/packages/core/src/shared/lifecycle.ts:106 (opens in a new tab)
disposeWithMe()
disposeWithMe(disposable): IDisposable
Parameters
Parameter | Type |
---|---|
disposable | DisposableLike |
Returns
Inherited from
Defined in
submodules/univer/packages/core/src/shared/lifecycle.ts:96 (opens in a new tab)
ensureNotDisposed()
protected ensureNotDisposed(): void
Returns
void
Inherited from
Defined in
submodules/univer/packages/core/src/shared/lifecycle.ts:100 (opens in a new tab)
getCurrentLocale()
getCurrentLocale(): LocaleType
Returns
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
Parameter | Type | Description |
---|---|---|
locales | ILocales | Locale 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
Parameter | Type |
---|---|
obj | ILanguagePack |
keys | string [] |
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
Parameter | Type |
---|---|
locale | LocaleType |
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
Parameter | Type | Description |
---|---|---|
key | string | the key to translate |
...args | string [] | 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)