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.