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
Overrides
Properties
Property | Modifier | Type | Default value | Inherited from | Defined in |
---|---|---|---|---|---|
_disposed | protected | boolean | false | Disposable ._disposed | packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:96 |
currentLocale$ | readonly | Observable <LocaleType > | undefined | - | packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:29 |
localeChanged$ | public | Subject <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
disposeWithMe()
disposeWithMe(disposable): IDisposable
Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:99
Parameters
Parameter | Type |
---|---|
disposable | DisposableLike |
Returns
Inherited from
ensureNotDisposed()
protected ensureNotDisposed(): void
Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/shared/lifecycle.ts:103
Returns
void
Inherited from
getCurrentLocale()
getCurrentLocale(): LocaleType
Defined in: packages/api/tmp/univer-pro/submodules/univer/packages/core/src/services/locale/locale.service.ts:101
Returns
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
Parameter | Type | Description |
---|---|---|
locales | ILocales | Locale 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
Parameter | Type |
---|---|
obj | ILanguagePack |
keys | string [] |
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
Parameter | Type |
---|---|
locale | LocaleType |
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
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'