Skip to content

Commit

Permalink
better browser language detection
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@15509 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 4, 2017
1 parent 931f851 commit 7c63616
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/html5/js/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,36 @@ var Utilities = {
return 'unknown';
},

getFirstBrowserLanguage : function () {
var nav = window.navigator,
browserLanguagePropertyKeys = ['language', 'browserLanguage', 'systemLanguage', 'userLanguage'],
i,
language;
// support for HTML 5.1 "navigator.languages"
if (Array.isArray(nav.languages)) {
for (i = 0; i < nav.languages.length; i++) {
language = nav.languages[i];
if (language && language.length) {
return language;
}
}
}
// support for other well known properties in browsers
for (i = 0; i < browserLanguagePropertyKeys.length; i++) {
language = nav[browserLanguagePropertyKeys[i]];
if (language && language.length) {
return language;
}
}
return null;
},

getKeyboardLayout: function() {
//IE:
//navigator.systemLanguage
//navigator.browserLanguage
var v = window.navigator.userLanguage || window.navigator.language;
var v = Utilities.getFirstBrowserLanguage();
console.debug("getFirstBrowserLanguage()=", v);
if (v==null) {
return "us";
}
//ie: v="en_GB";
v = v.split(',')[0];
var l = v.split('-', 2);
Expand Down

0 comments on commit 7c63616

Please sign in to comment.