Created
May 14, 2015 18:53
-
-
Save bmccormack/5109c70e2d321e7b4345 to your computer and use it in GitHub Desktop.
Get the preferred browser locale (language)
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
// This is hacky. Have fun. | |
var identity = function(value) { | |
return value; | |
}; | |
var compact = function(list) { | |
var results = []; | |
for (var i = 0; i < list.length; i++){ | |
if (identity(list[i])) results.push(list[i]); | |
} | |
return results; | |
}; | |
var preferred = [].concat.apply([],compact([ | |
navigator.language, // Safari, Chrome | |
(navigator.languages || []), // Chrome, Firefox | |
navigator.userLanguage, // Internet Explorer | |
navigator.browserLanguage, // Fallback? Not sure. | |
'en-GB' // Just in case | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment