Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TranslateService

Hierarchy

  • TranslateService

Index

Constructors

  • new TranslateService(store: TranslateStore, currentLoader: TranslateLoader, compiler: TranslateCompiler, parser: TranslateParser, missingTranslationHandler: MissingTranslationHandler, useDefaultLang: boolean, isolate: boolean, extend: boolean, defaultLanguage: string): TranslateService
  • Parameters

    • store: TranslateStore

      an instance of the store (that is supposed to be unique)

    • currentLoader: TranslateLoader

      An instance of the loader currently used

    • compiler: TranslateCompiler

      An instance of the compiler currently used

    • parser: TranslateParser

      An instance of the parser currently used

    • missingTranslationHandler: MissingTranslationHandler

      A handler for missing translations.

    • useDefaultLang: boolean

      whether we should use default language translation when current language translation is missing.

    • isolate: boolean

      whether this service should use the store or not

    • extend: boolean

      To make a child module extend (and use) translations from parent modules.

    • defaultLanguage: string

      Set the default language using configuration

    Returns TranslateService

Properties

_currentLang: any
_defaultLang: any
_langs: any
_onDefaultLangChange: any
_onLangChange: any
_onTranslationChange: any
_translationRequests: any
_translations: any
changeDefaultLang: any

Changes the default lang

changeLang: any

Changes the current lang

compiler: TranslateCompiler
currentLoader: TranslateLoader
extend: any
isolate: any
loadingTranslations: any
missingTranslationHandler: MissingTranslationHandler
parser: TranslateParser
pending: any
retrieveTranslations: any

Retrieves the given translations

store: TranslateStore
updateLangs: any

Update the list of available langs

useDefaultLang: any
ɵfac: unknown
ɵprov: ɵɵInjectableDeclaration<TranslateService>

Accessors

  • get currentLang(): string
  • set currentLang(currentLang: string): void
  • The lang currently used

    Returns string

  • The lang currently used

    Parameters

    • currentLang: string

    Returns void

  • get defaultLang(): string
  • set defaultLang(defaultLang: string): void
  • The default lang to fallback when translations are missing on the current lang

    Returns string

  • The default lang to fallback when translations are missing on the current lang

    Parameters

    • defaultLang: string

    Returns void

  • get langs(): string[]
  • set langs(langs: string[]): void
  • an array of langs

    Returns string[]

  • an array of langs

    Parameters

    • langs: string[]

    Returns void

  • get onDefaultLangChange(): EventEmitter<DefaultLangChangeEvent>
  • An EventEmitter to listen to default lang change events onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => { // do something });

    Returns EventEmitter<DefaultLangChangeEvent>

  • get onLangChange(): EventEmitter<LangChangeEvent>
  • An EventEmitter to listen to lang change events onLangChange.subscribe((params: LangChangeEvent) => { // do something });

    Returns EventEmitter<LangChangeEvent>

  • get onTranslationChange(): EventEmitter<TranslationChangeEvent>
  • An EventEmitter to listen to translation change events onTranslationChange.subscribe((params: TranslationChangeEvent) => { // do something });

    Returns EventEmitter<TranslationChangeEvent>

  • get translations(): any
  • set translations(translations: any): void
  • a list of translations per lang

    Returns any

  • a list of translations per lang

    Parameters

    • translations: any

    Returns void

Methods

  • addLangs(langs: string[]): void
  • Add available langs

    Parameters

    • langs: string[]

    Returns void

  • get(key: string | string[], interpolateParams?: Object): Observable<any>
  • Gets the translated value of a key (or an array of keys)

    Parameters

    • key: string | string[]
    • Optional interpolateParams: Object

    Returns Observable<any>

    the translated key, or an object of translated keys

  • getBrowserCultureLang(): undefined | string
  • Returns the culture language code name from the browser, e.g. "de-DE"

    Returns undefined | string

  • getBrowserLang(): undefined | string
  • Returns the language code name from the browser, e.g. "de"

    Returns undefined | string

  • getDefaultLang(): string
  • Gets the default language used

    Returns string

  • getLangs(): string[]
  • Returns an array of currently available langs

    Returns string[]

  • getParsedResult(translations: any, key: any, interpolateParams?: Object): any
  • Returns the parsed result of the translations

    Parameters

    • translations: any
    • key: any
    • Optional interpolateParams: Object

    Returns any

  • getStreamOnTranslationChange(key: string | string[], interpolateParams?: Object): Observable<any>
  • Returns a stream of translated values of a key (or an array of keys) which updates whenever the translation changes.

    Parameters

    • key: string | string[]
    • Optional interpolateParams: Object

    Returns Observable<any>

    A stream of the translated key, or an object of translated keys

  • getTranslation(lang: string): Observable<any>
  • Gets an object of translations for a given language with the current loader and passes it through the compiler

    Parameters

    • lang: string

    Returns Observable<any>

  • instant(key: string | string[], interpolateParams?: Object): any
  • Returns a translation instantly from the internal state of loaded translation. All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling.

    Parameters

    • key: string | string[]
    • Optional interpolateParams: Object

    Returns any

  • reloadLang(lang: string): Observable<any>
  • Allows to reload the lang file from the file

    Parameters

    • lang: string

    Returns Observable<any>

  • resetLang(lang: string): void
  • Deletes inner translation

    Parameters

    • lang: string

    Returns void

  • set(key: string, value: string, lang?: string): void
  • Sets the translated value of a key, after compiling it

    Parameters

    • key: string
    • value: string
    • Optional lang: string

    Returns void

  • setDefaultLang(lang: string): void
  • Sets the default language to use as a fallback

    Parameters

    • lang: string

    Returns void

  • setTranslation(lang: string, translations: Object, shouldMerge?: boolean): void
  • Manually sets an object of translations for a given language after passing it through the compiler

    Parameters

    • lang: string
    • translations: Object
    • Optional shouldMerge: boolean

    Returns void

  • stream(key: string | string[], interpolateParams?: Object): Observable<any>
  • Returns a stream of translated values of a key (or an array of keys) which updates whenever the language changes.

    Parameters

    • key: string | string[]
    • Optional interpolateParams: Object

    Returns Observable<any>

    A stream of the translated key, or an object of translated keys

  • use(lang: string): Observable<any>
  • Changes the lang currently used

    Parameters

    • lang: string

    Returns Observable<any>

Generated using TypeDoc