Language API

A list of TranslocoService language-related API methods and their usages

getDefaultLang()

Returns the default language of the application.

app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    const defaultLang = translocoService.getDefaultLang();
    console.log(defaultLang);
  }
}

setDefaultLang()

Sets the default language.

app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.setDefaultLang('es');
  }
}

getActiveLang()

Returns the current active language.


setActiveLang()

Sets the active language for the application.


getAvailableLangs()

Retrieves the list of available languages.


setFallbackLangForMissingTranslation()

Defines a fallback language to be used when a translation key is missing for the active language.

Note If you provide an array, only the first language is used. Fallback translations for missing keys support a single language.


setAvailableLangs()

Sets the list of available languages.


langChanges$

An observable that emits whenever the active language changes.

Note langChanges$ will emit the currently active language immediately upon subscription.


load()

Loads the specified language and adds it to the service.

Was this helpful?