I need to detect OS language using javascript so I can view my page depending on the language.
I know that we can detect the browser language but that is not enough for me.
I need Operation System language
Thanks in advance
In JavaScript, the navigator object returns the browser information. Technically, through the navigator properties, we send information about the browser and sometimes information about the app or operating system we are using to the server.
To detect the operating system on the client machine, one can simply use navigator. appVersion or navigator. userAgent property. The Navigator appVersion property is a read-only property and it returns a string which represents the version information of the browser.
Open the browser settings, and in the advanced section scroll down to find Languages . Open Language and Input Settings and add the language or language+region choice you want from the list available. Order the resulting list so that it is in descending order of preference. You don't need to restart Chrome.
The Navigator language property is used for returning the browser's language version. It is a read-only property and it returns a string representing the language version of the browser. Some of the possible language codes are : en-US.
There is no cross-browser way to do this. Internet Explorer supports the following:
navigator.browserLanguage
: browser languagenavigator.systemLanguage
: Windows system languagenavigator.userLanguage
: Windows user-specific languageBut there is no way to access these settings from any other browsers (that I can tell) so don't use them: stick to the standard navigator.language
(corresponding to the browser language) if you want to maintain cross-browser functionality. If you do use them you will tie your web site to a specific family of operating systems (i.e. Windows) and a specific browser (i.e. Internet Explorer). Do you really want to do this?
Why is the browser language insufficient for your application?
You may just guess OS language considering few factors:
navigator.browserLanguage
: IE language (menu, help and etc.), the same as OS display language (if user hasn't change it). As in Control Panel -> Region and Language -> Keyboards and Lanugages -> Display languagenavigator.systemLanguage
: as in Control Panel -> Region and Language -> Locationnavigator.userLanguage
: as in Control Panel -> Region and Language -> Formatsvar d=new Date(Date.UTC(2014,1,26,3,0,0));
var dateFormat={weekday:"long",year:"numeric",month:"long",day:"numeric"};
var result = d.toLocaleDateString("i-default",dateFormat);
alert(result);
//e.g. for Russian format ( Control Panel -> Region and Language -> Formats )
//result == 'среда, 26 февраля 2014 г.'
Then search result
on your server over preliminary generated set of formatted dates in different languages.
NB! Chrome returns date formatted in its UI language.
If you desperately need to know OS language — embed flash in your page and exploit flash.system.Capabilities.language:
NB! Chrome doesn't allow the trick — Chrome's Flash always shows browser.language
, I think because it has own Flash.
navigator.language
tells you a browser's UI language (menu, help and etc.) and you may assume that in overwhelming majority of cases it matches OS language (especially for home computers): while downloading FF or Chrome a download page is displayed according user's then browser — on Windows it is IE in the same language as OS.
It is very strange indeed that Chrome is thing in itself when dealing with browser's environment parameters, alas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With