Skip to content

Instantly share code, notes, and snippets.

@asleepwalker
Last active August 23, 2016 14:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asleepwalker/a821c314e86e9b3a6874 to your computer and use it in GitHub Desktop.
Save asleepwalker/a821c314e86e9b3a6874 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