admin管理员组文章数量:1323323
I've been trying to get momentjs to correctly detect the browser language and localise the time displays. (as per Locale detection with Moment.js)
But I have been having a bit of trouble getting the correct locale out of chrome.
It seems like chrome has the correct list of languages configured for my browser in navigator.languages
but navigator.language
is returning something pletely different.
I'm guessing either I have chrome setup wrong (which doesn't seem likely given the correct languages are in navigator.languages
) or the method for selecting the browser language isn't quite right?
Is there a different way I should be using to get the language other than window.navigator.userLanguage || window.navigator.language
?
I've been trying to get momentjs to correctly detect the browser language and localise the time displays. (as per Locale detection with Moment.js)
But I have been having a bit of trouble getting the correct locale out of chrome.
It seems like chrome has the correct list of languages configured for my browser in navigator.languages
but navigator.language
is returning something pletely different.
I'm guessing either I have chrome setup wrong (which doesn't seem likely given the correct languages are in navigator.languages
) or the method for selecting the browser language isn't quite right?
Is there a different way I should be using to get the language other than window.navigator.userLanguage || window.navigator.language
?
- en-GB is the proper language/locale, it stands for english great britain. – Wobbles Commented Oct 18, 2015 at 23:07
- Language is pletely independent of "locale". But don't tell the W3C that. – RobG Commented Oct 18, 2015 at 23:46
1 Answer
Reset to default 5The W3C draft states that:
navigator.language
is the user's "preferred language" or a "plausible language". This is not necessarily the same asnavigator.languages[0]
.navigator.languages
lists the "user's preferred languages, with the most preferred language first". It is expected to have the same value as theAccept-Language
header.
By the looks of quickly experimenting in a VM, navigator.languages[0]
leads to the most accurate results, navigator.language
being the language of the OS.
It looks as if the "en-GB"
you are getting refers to the language of the user, whereas the "en-NZ"
refers to the user locale (number & date/time formatting).
Since this is still a draft, the results you get may change with implementation.
本文标签: javascriptRetrieving browser language in chromeStack Overflow
版权声明:本文标题:javascript - Retrieving browser language in chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142711a2422654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论