Skip to content

SiTranslateService documentation

Wrapper around an actual translation framework which is meant to be used internally by Element. Applications must not use this service.

Use injectSiTranslateService to get an instance of the translation service.

Attributes and Methods

NameTypeDefaultDescription
availableLanguages
string[]The available languages.
(readonly) currentLanguage
stringThe currently used language.
getDefaultLanguage()
() => stringThe language to be used as default.
Returns The code of the default language.
prevent$LocalizeInit
Optional
boolean
setCurrentLanguage(...)
(lang: string) => Observable<void>Sets a new language to be used. If needed, loads the language file.
Returns An observable that emits when the new language is loaded and activated.

Parameters
  • lang: string  The language to be used.
setDefaultLanguage(...)
(lang: string) => voidThe language to be used as default.

Parameters
  • lang: string  The language code.
setDocumentLanguage(...)
(lang: string) => voidParameters
setTranslation(...)
Optional
(key: string, value: string) => voidIf supported by the underlying translation library, this method can be used to add a translation for a specific key.
It is intended to be used for adding the english default value.
It will be called whenever a key within element is resolved.
An implementation of this method must check that it does not override an existing translation.

Parameters
translate(...)
<(T: (string | string[]))> (keys: T, params: Record<string, unknown>) => (TranslationResult<T> | Observable<TranslationResult<T>>)Translates the key(s) by using the underlying translation library.
Returns Returns the translated key or an object with the translated keys. Depending on the underlying translation library (sync/async) the result will be wrapped in an Observable.

Parameters
  • keys: T  A single translation key or an array of keys.
  • params: Record<string, unknown>  Parameters to be replaced within the translation text.
translateAsync(...)
<(T: (string | string[]))> (keys: T, params: Record<string, unknown>) => Observable<TranslationResult<T>>Translates the key(s) by using the underlying translation library in an asynchronous manner. It will emit each time the active language is changed.
Returns Returns the translated key or an object with the translated keys wrapped in an Observable.

Parameters
  • keys: T  A single translation key or an array of keys.
  • params: Record<string, unknown>  Parameters to be replaced within the translation text.
translateSync(...)
<(T: (string | string[]))> (keys: T, params: Record<string, unknown>) => TranslationResult<T>Translates the key(s) by using the underlying translation library in a synchronous manner.

Warning: The caller of this function needs to make sure the translation file(s) are already loaded. It is generally not recommended to use this function unless you know exactly what you are doing.

Returns Returns the translated key or an object with the translated keys.

Parameters
  • keys: T  A single translation key or an array of keys.
  • params: Record<string, unknown>  Parameters to be replaced within the translation text.
(readonly) translationChange
Observable<void>If the underlying translation library supports switching the language and/or updating the translation texts, this observable will emit. There is no initial emit.

Types Documentation


Except where otherwise noted, content on this site is licensed under MIT License.