question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get current language with translate.getBrowserLang(), it always return the same value

See original GitHub issue

I want to get current language with this.translate.getBrowserLang() , but it always return ‘en’, but the app’s language actually changed, here is the plunkr https://plnkr.co/edit/JEXgj8WcISYGtDg75VoR?p=preview ,and this is from the demo plunkr

here is my version:

"@ngx-translate/core": "^6.0.0",
"@ngx-translate/http-loader": "^0.0.3",

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

5reactions
guntramcommented, May 8, 2017

.getBrowserLang() returns the FIRST default browser language. I just changed my chrome from "de" to "en"…ok…working. I wanted to change back to "de", but the german language was gone in the chrome settings, so i added it again and set it as the default browser language. After all of that, the .getBrowserLang() still returns "en", because my "de" setting was the last of three ["en-us", "en", "de"], and the .getBrowserLang() only returns the first browser language, but NOT the one which is set as the default language.

5reactions
ocombecommented, Mar 9, 2017

Like its name suggests, getBrowserLang returns the lang of the browser. If you want the lang setup for your application use this.translate.currentLang.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get current language with ngx-translate in angular2
I want to get current language with this.translate.getBrowserLang() , but it always return 'en', whatever the current language is and what ...
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
Angular Localization Using ngx-translate - Telerik
Use the below method of TranslateService to get current browser language to set the default language. const currentLanguage = this.translate.
Read more >
Using ngx-translate to switch the language of a Form in your ...
Now since i have used just 2 languages, I will have 2 json files located in the i18n folder in the assets folder....
Read more >
@ngx-translate/core - npm
Define the default language for the application ... Without any onTranslationChange events this returns the same value as get but it will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found