Last active
August 23, 2016 14:26
-
-
Save asleepwalker/a821c314e86e9b3a6874 to your computer and use it in GitHub Desktop.
Boilerplate browser locale detector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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