Skip to content

Instantly share code, notes, and snippets.

@wowkin2
Forked from asleepwalker/get-browser-locale.js
Created August 23, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wowkin2/9857a56a27f4e1fb646451ee4d06dbee to your computer and use it in GitHub Desktop.
Save wowkin2/9857a56a27f4e1fb646451ee4d06dbee to your computer and use it in GitHub Desktop.
Boilerplate browser locale detector
function getLocale() {
var lang;
if (navigator.languages) {
// chrome does not currently set navigator.language correctly https://code.google.com/p/chromium/issues/detail?id=101138
// but it does set the first element of navigator.languages correctly
lang = navigator.languages[0];
} else if (navigator.userLanguage) {
// IE only
lang = navigator.userLanguage;
} else {
// as of this writing the latest version of firefox + safari set this correctly
lang = navigator.language;
}
return lang;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment