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
NGX-Translate is an internationalization library for Angular. It lets you define translations for your content in different languages and switch between them easily. Check out the demo on StackBlitz. It gives you access to a service, a directive and a pipe to handle any dynamic or static content.
Create an entry in the translation file (assets/i18n/en. json). The string interpolation syntax {{ }} is used to indicate a named parameter.
The service also contains a method called translate. It is later called by the pipe to get the translation for a specific key. It always uses the language specified in the 'language'-variable of the service, to lookup the translation. That's it.
import translate service and add in constructor
constructor(private translate: TranslateService){ }
I find it use this.translate.currentLang
to get the 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