For the project, I have to provide two versions of the web page: one English and one French. Since I'm in the UK, the browser (IE11) is naturally installed in the local language (en-GB). To check french, I went to
Internet-Options->Languages->Set Language Preference->Add a Language (French-France) (or select the language if already there)
and make sure that French is at the top. I have a JSF page where the language is detected using Java, and it works fine, all the text is taken from the properties file of France, not the properties file in English, which automatically switches when changing the language between English and French. However, for one webpage I need to determine the current language in JavaScript, and whatever I try, it remains en-GB.
I tried this code:
var language = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage;
It returns 'en-GB'. I tried it myself in the F12 debugger:
navigator.languages returns: undefined navigator.userLanguage: en-GB navigator.language: undefined navigator.browserLanguage: en-US
This is IE11 version 11.0.9600.17031
I am also in Windows 8, and on the Windows main screen (after accidentally pressing the Windows key ...) everything is also displayed in French (news, weather, etc.), so the French language is selected, but how to determine this in JavaScript?
source share