Created
February 15, 2013 02:11
-
-
Save MaraScott/4958103 to your computer and use it in GitHub Desktop.
Name : getBrowserLanguage() - Language : Javascript - type : function - Platform : generic - tag : browser, lang
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
// get browser language in this format US, FR, ... | |
var getBrowserLanguage = function (){ | |
"use strict"; | |
// navigator.userLanguage for IE, navigator.language for others | |
var lang = navigator.language || navigator.userLanguage; | |
lang = lang.split('-'); | |
return lang[1]; | |
}; // END FUNC | |
// example | |
console.log(getBrowserLanguage()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
navigator.language is supported by all browsers now.
navigator.language // output string ie: en-GB