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 completely 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
?
The W3C draft states that:
navigator.language
is the user's "preferred language" or a "plausible language". This is not necessarily the same as navigator.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 the Accept-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.
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