For a project I have to provide 2 versions of a webpage: one English and one French. As I'm in the UK, the browser (IE11) is naturally installed in the local language (en-GB). To test 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 French is at the top. I have a JSF page where the language is detected using Java, and that works fine, all text is taken from the French properties file, rather than the English properties file, switching automatically when changing the language between English and French. However, for one web page I need to detect 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'. Tried on its own 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'm also in Windows 8, and the windows-home screen (after accidentally pressing on the windows key...) also shows everything in French (news, weather etc), so French is selected, but how to detect it in JavaScript?