How can I get user language locale id?
I can retrieved the language locale name by using navigator.browserLanguage
but how can I retrieve the ID?
For example, if user navigator.browserLanguage
is en-US I want to get 1033
How can I get user language locale id?
I can retrieved the language locale name by using navigator.browserLanguage
but how can I retrieve the ID?
For example, if user navigator.browserLanguage
is en-US I want to get 1033
This answer here suggests as follows.
You may take the information from the horse's mouth, i.e. http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx, and copy-pasted it (through Excel) into a .properties file like this:
1078 = Afrikaans - South Africa
1052 = Albanian - Albania
1118 = Amharic - Ethiopia
1025 = Arabic - Saudi Arabia
5121 = Arabic - Algeria
...
(You can download the file here if you have similar needs.)
You can probably create an object with keys and quickly access them when required.
Disclaimer: this really is a minimalistic, "dummy" way of doing it yourself in JavaScript, and obviously keeping (and maintaining) a copy of the LCID mapping information in your own code base is not very elegant. (On the other hand, neither would you want to include a huge library jar or do anything overly complicated just for this simple mapping.) So despite this answer, feel free to post more elegant solutions or existing libraries if you know of anything like that.
Off-topic: navigator.browserLanguage
is IE only. You would be better off using navigator.userLanguage || navigator.language
, in the browser.