Improve Manager lang selection to use browser preferences (#1584)
This commit is contained in:
parent
e08d0a78e6
commit
6cffe855a2
|
@ -35,14 +35,19 @@ llapp.provider '$translator', ->
|
||||||
if navigator.languages
|
if navigator.languages
|
||||||
nlangs = navigator.languages
|
nlangs = navigator.languages
|
||||||
for nl in nlangs
|
for nl in nlangs
|
||||||
|
console.log 'Navigator lang', nl
|
||||||
for al in window.availableLanguages
|
for al in window.availableLanguages
|
||||||
if al == nl
|
console.log ' Available lang', al
|
||||||
|
re = new RegExp('^'+al+'-?')
|
||||||
|
if nl.match re
|
||||||
|
console.log ' Matching lang =', al
|
||||||
langs.push al
|
langs.push al
|
||||||
else if al.substring(0, 1) == nl.substring(0, 1)
|
else if al.substring(0, 1) == nl.substring(0, 1)
|
||||||
langs2.push al
|
langs2.push al
|
||||||
res.lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else 'en'
|
res.lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else 'en'
|
||||||
else
|
else
|
||||||
res.lang = 'en'
|
res.lang = 'en'
|
||||||
|
console.log 'Selected lang ->', res.lang
|
||||||
|
|
||||||
# Internal properties
|
# Internal properties
|
||||||
res.deferredTr = []
|
res.deferredTr = []
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Generated by CoffeeScript 1.10.0
|
// Generated by CoffeeScript 1.12.7
|
||||||
|
|
||||||
/*
|
/*
|
||||||
LemonLDAP::NG base app module
|
LemonLDAP::NG base app module
|
||||||
|
@ -17,7 +17,7 @@ LemonLDAP::NG base app module
|
||||||
llapp = angular.module('llApp', ['ngAria']);
|
llapp = angular.module('llApp', ['ngAria']);
|
||||||
|
|
||||||
llapp.provider('$translator', function() {
|
llapp.provider('$translator', function() {
|
||||||
var al, c, j, k, langs, langs2, len, len1, nl, nlangs, ref, res;
|
var al, c, j, k, langs, langs2, len, len1, nl, nlangs, re, ref, res;
|
||||||
res = {};
|
res = {};
|
||||||
c = decodeURIComponent(document.cookie);
|
c = decodeURIComponent(document.cookie);
|
||||||
if (c.match(/llnglanguage=(\w+)/)) {
|
if (c.match(/llnglanguage=(\w+)/)) {
|
||||||
|
@ -31,10 +31,14 @@ LemonLDAP::NG base app module
|
||||||
}
|
}
|
||||||
for (j = 0, len = nlangs.length; j < len; j++) {
|
for (j = 0, len = nlangs.length; j < len; j++) {
|
||||||
nl = nlangs[j];
|
nl = nlangs[j];
|
||||||
|
console.log('Navigator lang', nl);
|
||||||
ref = window.availableLanguages;
|
ref = window.availableLanguages;
|
||||||
for (k = 0, len1 = ref.length; k < len1; k++) {
|
for (k = 0, len1 = ref.length; k < len1; k++) {
|
||||||
al = ref[k];
|
al = ref[k];
|
||||||
if (al === nl) {
|
console.log(' Available lang', al);
|
||||||
|
re = new RegExp('^' + al + '-?');
|
||||||
|
if (nl.match(re)) {
|
||||||
|
console.log(' Matching lang =', al);
|
||||||
langs.push(al);
|
langs.push(al);
|
||||||
} else if (al.substring(0, 1) === nl.substring(0, 1)) {
|
} else if (al.substring(0, 1) === nl.substring(0, 1)) {
|
||||||
langs2.push(al);
|
langs2.push(al);
|
||||||
|
@ -45,6 +49,7 @@ LemonLDAP::NG base app module
|
||||||
} else {
|
} else {
|
||||||
res.lang = 'en';
|
res.lang = 'en';
|
||||||
}
|
}
|
||||||
|
console.log('Selected lang ->', res.lang);
|
||||||
res.deferredTr = [];
|
res.deferredTr = [];
|
||||||
res.translationFields = {};
|
res.translationFields = {};
|
||||||
res.translate = function(s) {
|
res.translate = function(s) {
|
||||||
|
@ -153,7 +158,7 @@ LemonLDAP::NG base app module
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
terminal: true,
|
terminal: true,
|
||||||
compile: function(element, attr) {
|
compile: function(element, attr) {
|
||||||
var e, error, t;
|
var e, t;
|
||||||
if (t = attr.type.match(/text\/(menu|parameters)/)) {
|
if (t = attr.type.match(/text\/(menu|parameters)/)) {
|
||||||
try {
|
try {
|
||||||
return $htmlParams.set(t[1], JSON.parse(element[0].text));
|
return $htmlParams.set(t[1], JSON.parse(element[0].text));
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user