This question already has an answer here:
I have been trying to detect the browser language preference using JavaScript.
If I set the browser language in IE in Tools>Internet Options>General>Languages
, how do I read this value using JavaScript?
Same problem for Firefox. I'm not able to detect the setting for tools>options>content>languages
using navigator.language
.
Using navigator.userLanguage
, it detects the setting done thru
Start>ControlPanel>RegionalandLanguageOptions>Regional Options
tab.
I have tested with navigator.browserLanguage
and navigator.systemLanguage
but neither returns the value for the first setting(Tools>InternetOptions>General>Languages
)
I found a link which discusses this in detail, but the question remains unanswered :(
If you only need to support certain modern browsers then you can now use:
which returns an array of the user's language preferences in the order specified by the user.
As of now (Sep 2014) this works on: Chrome (v37), Firefox (v32) and Opera (v24)
But not on: IE (v11)
navigator.userLanguage
for IEwindow.navigator.language
for firefox/opera/safariJavascript way:
If you are using jQuery.i18n plugin, you can use:
DanSingerman has a very good solution for this question.
The only reliable source for the language is in the HTTP-request header. So you need a server-side script to reply the request-header or at least the
Accept-Language
field back to you.Here is a very simple Node.js server which should be compatible with DanSingermans jQuery plugin.
For who are looking for Java Server solution
Here is RestEasy
I came across this piece of code to detect browser's language in Angular Translate module, which you can find the source here. I slightly modified the code by replacing angular.isArray with Array.isArray to make it independent of Angular library.