Core: Get Current Language Observable

Created on 14 Mar 2019  路  1Comment  路  Source: ngx-translate/core

Current behavior


Based on the answer the only way of getting the currently set language is to call this.translate.currenctLang which returns a plain string

Expected behavior


Let's imagine an observable property of the current language

currenctLang$: Observable<string>;

or a method returning an observable wrapping the current language

getCurrenctLang$: () => Observable<string>;

What is the motivation / use case for changing the behavior?


This would give you the ability to listen for changes in the language, which is useful for creating a custom pipe for example

How do you think that we should implement this?


A Subject may be used to both observe the current language and emit new values

Most helpful comment

To listen to changes you can use onLangChange emitter.

onLangChange.subscribe((event: LangChangeEvent) => {
  // do something
});

>All comments

To listen to changes you can use onLangChange emitter.

onLangChange.subscribe((event: LangChangeEvent) => {
  // do something
});
Was this page helpful?
0 / 5 - 0 ratings