Select lang from queryString (#2136)

This commit is contained in:
Christophe Maudoux 2020-04-13 10:55:56 +02:00
parent f4976d85fa
commit b4e2b64f49
4 changed files with 40 additions and 7 deletions

View File

@ -296,10 +296,18 @@ $(window).on 'load', () ->
$("p.removeOther a").attr "href", link
# Language detection. Priority order:
# 0 - llnglanguage parameter
# 1 - cookie value
# 2 - first navigator.languages item that exists in window.availableLanguages
# 3 - first value of window.availableLanguages
lang = getCookie 'llnglanguage'
queryString = window.location.search
console.log 'Parsed queryString:', queryString
urlParams = new URLSearchParams queryString if queryString
lang = urlParams.get('llnglanguage') if urlParams
console.log 'Get lang from parameter' if lang
if !lang
lang = getCookie 'llnglanguage'
console.log 'Get lang from cookie' if lang
if !lang
if navigator
langs = []
@ -320,10 +328,13 @@ $(window).on 'load', () ->
else if al.substring(0, 1) == nl.substring(0, 1)
langs2.push al
lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else window.availableLanguages[0]
console.log 'Get lang from navigator' if lang
else
lang = window.availableLanguages[0]
console.log 'Get lang from window' if lang
else if lang not in window.availableLanguages
lang = window.availableLanguages[0]
console.log 'Get default lang'
console.log 'Selected lang ->', lang
setCookie 'llnglanguage', lang
translatePage(lang)

View File

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.12.8
// Generated by CoffeeScript 1.12.7
/*
LemonLDAP::NG Portal jQuery scripts
@ -223,7 +223,7 @@ LemonLDAP::NG Portal jQuery scripts
datas = {};
$(window).on('load', function() {
var action, al, authMenuIndex, authMenuTabs, back_url, i, l, lang, langdiv, langs, langs2, len, len1, len2, len3, link, m, menuIndex, menuTabs, method, n, nl, nlangs, re, ref, ref1, ref2;
var action, al, authMenuIndex, authMenuTabs, back_url, i, l, lang, langdiv, langs, langs2, len, len1, len2, len3, link, m, menuIndex, menuTabs, method, n, nl, nlangs, queryString, re, ref, ref1, ref2, urlParams;
datas = getValues();
window.datas = datas;
$("#appslist").sortable({
@ -283,7 +283,23 @@ LemonLDAP::NG Portal jQuery scripts
link = $("p.removeOther a").attr("href") + "&method=" + method + "&url=" + btoa(back_url);
$("p.removeOther a").attr("href", link);
}
lang = getCookie('llnglanguage');
queryString = window.location.search;
console.log('Parsed queryString:', queryString);
if (queryString) {
urlParams = new URLSearchParams(queryString);
}
if (urlParams) {
lang = urlParams.get('llnglanguage');
}
if (lang) {
console.log('Get lang from parameter');
}
if (!lang) {
lang = getCookie('llnglanguage');
if (lang) {
console.log('Get lang from cookie');
}
}
if (!lang) {
if (navigator) {
langs = [];
@ -314,11 +330,18 @@ LemonLDAP::NG Portal jQuery scripts
}
}
lang = langs[0] ? langs[0] : langs2[0] ? langs2[0] : window.availableLanguages[0];
if (lang) {
console.log('Get lang from navigator');
}
} else {
lang = window.availableLanguages[0];
if (lang) {
console.log('Get lang from window');
}
}
} else if (indexOf.call(window.availableLanguages, lang) < 0) {
lang = window.availableLanguages[0];
console.log('Get default lang');
}
console.log('Selected lang ->', lang);
setCookie('llnglanguage', lang);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long