I'm using ngx-translate. I changed my OS language to german, but still when I print out this.translate.getBrowserLang()
it returns 'en'.
protected myMethod() {
this.translate.setDefaultLang( 'en' );
this.translate.use( 'de' );
console.log( 'Browser Lang', this.translate.getBrowserLang());
}
but when I use
console.log( 'Browser Lang', navigator.language)
it prints 'de' as expected.
What am I doing wrong?
Also is there a way to automatically detect and switch the language in ngx-translate?
.getBrowserLang()
returns the FIRST default browser language.
And navigator.language
return the current user navigator language preference.
So use navigator.language
is the best way to detect user current language
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With