The navigator object provides information about the browser, as there is no public standard applies to this object, there is quite different implementations for navigator in all major browsers, and so it is the same about browser language exposed in this object.
navigator.language
returns the language of the browser, but it is not user preference language through browser settings. Different browser has different implementation as of writing, like Chrome always returns browser language, while Firefox returns the first preference language.
navigator.languages
This is new and well supported in Chrome and Firefox, which returns all browser preference languages. The value is an array.
For example, one return value is
Array [ "zh", "pt-BR", "es-AR", "fr", "zh-TW", "en", "pt", "ja", "en-US" ]
which maps to Http header Accept-Language
zh,pt-BR;q=0.9,es-AR;q=0.8,fr;q=0.7,zh-TW;q=0.6,en;q=0.4,pt;q=0.3,ja;q=0.2,en-US;q=0.1
This new property added to navigator object gives javascript developer more power to do i18n for web application. We can quickly know user's preference language for this browser, then show translated version based on the first value appears in languages array.
Internet Explorer has the following three language related properties.
navigator.userLanguageRetrieves the operating system's natural language setting.
navigator.systemLanguage
Retrieves the default language used by the operating system.
navigator.browserLanguage
Retrieves the current operating system language.
Note that IE10 or early versions don't provide a navigator.language property like other major browsers. Check MSDN online document for details.
https://msdn.microsoft.com/en-us/library/ms535867(v=vs.85).aspx
No comments:
Post a Comment