Get current chrome language

I determine the current browser locale using this API:

var language = window.navigator.userLanguage || window.navigator.language; 

This returns “fr-FR” in IE, but it only returns “fr” in Chrome (and similarly for other locales).

Is there any other API that will return "fr-FR" in chrome? We rely on this to download the appropriate culture files.

+7
javascript google-chrome locale
source share
2 answers

Firefox and Chrome have an array of languages on the navigator object. Usually the first element in this array is the locale selected by the user (usually inherited from the OS settings).

 var language; if (window.navigator.languages) { language = window.navigator.languages[0]; } else { language = window.navigator.userLanguage || window.navigator.language; } 

The navigator.languages array for chrome is ["en-GB", "en-US", "en"] for me, while navigator.language = "en-US" is a bit different but important

+6
source share

In the latest versions of the Chrome browser,
he var language = window.navigator.userLanguage || window.navigator.language; var language = window.navigator.userLanguage || window.navigator.language; returns 'fr-FR'.

If you are still facing the same problem, you can try var language = navigator.language;

+3
source share

All Articles