views:

52

answers:

2

Hi

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

A: 

You can use the user agent. However, it can be spoofed easily, it is not guaranteed to contain language information, and navigator.language and navigator.browserLanguage will probably be more reliable.

Matthew Flaschen
He's talking about the locale, I think.
Pointy
`navigator.language` or `navigator.browserLanguage`, it's never been standardized: https://developer.mozilla.org/en/Navigator.language, http://msdn.microsoft.com/en-us/library/ms533542(v=VS.85).aspx IE also provides `systemLanguage` and `userLanguage`
T.J. Crowder
+3  A: 

There is no cross-browser way to do this. Internet Explorer supports the following:

  • navigator.browserLanguage: browser language
  • navigator.systemLanguage: Windows system language
  • navigator.userLanguage: Windows user-specific language

But 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?

Richard Cook
I am looking for navigator.systemLanguage , can I use it with firefox or just IE??
SzamDev
No, IE only I'm afraid. However, this stuff is complicated. However, I think you should think long and hard about why the browser's language is not sufficient.
Richard Cook
@SzamDev: Firefox provides `navigator.language`, which is much the same thing, see Matthew's answer.
T.J. Crowder
@T.J. `navigator.language` is equivalent to `navigator.browserLanguage`.
Matthew Flaschen
about your question, Why is the browser language insufficient for your application? I have pages for each language, I want after detect the OS language to redirect to this page or display it because sometime the browser language maybe not the same of OS
SzamDev
@SzamDev: That's your user's problem, not yours. If they're lying to you, well, they should fix that. You're dealing with the browser, so that's the language you should be dealing with.
T.J. Crowder