How to get current language with ngx-translate in angular2

Allen picture Allen · Mar 9, 2017 · Viewed 28.2k times · Source

I want to get current language with this.translate.getBrowserLang(), but it always return 'en', whatever the current language is and what the supported languages is.

Here is the plnkr: https://plnkr.co/edit/JEXgj8WcISYGtDg75VoR?p=preview,


maybe plnkr has broken, you can try stackblitz: https://stackblitz.com/edit/github-kk1mud-a7gxbb

Answer

Allen picture Allen · Mar 9, 2017

import translate service and add in constructor

constructor(private translate: TranslateService){
}

I find it use this.translate.currentLang to get the current language