Created
April 20, 2018 03:20
-
-
Save miguelmota/00830090539e74a6d0ace112717fc498 to your computer and use it in GitHub Desktop.
JavaScript browser locale
This file contains 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 browserLocale() { | |
var lang; | |
if (navigator.languages && navigator.languages.length) { | |
// latest versions of Chrome and Firefox set this correctly | |
lang = navigator.languages[0] | |
} else if (navigator.userLanguage) { | |
// IE only | |
lang = navigator.userLanguage | |
} else { | |
// latest versions of Chrome, Firefox, and 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