mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Fixed userlang control in the viewer
Now the viewer stores the userlang preference in window.localStorage.
This commit is contained in:
@ -69,30 +69,19 @@ function $t(msgId, params={}) {
|
||||
}
|
||||
}
|
||||
|
||||
function getCookie(cookieName) {
|
||||
const name = cookieName + "=";
|
||||
let result;
|
||||
decodeURIComponent(document.cookie).split('; ').forEach(val => {
|
||||
if (val.indexOf(name) === 0) {
|
||||
result = val.substring(name.length);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const DEFAULT_UI_LANGUAGE = 'en';
|
||||
|
||||
Translations.load(DEFAULT_UI_LANGUAGE, /*asDefault=*/true);
|
||||
|
||||
function getUserLanguage() {
|
||||
return new URLSearchParams(window.location.search).get('userlang')
|
||||
|| getCookie('userlang')
|
||||
|| window.localStorage.getItem('userlang')
|
||||
|| viewerSettings.defaultUserLanguage
|
||||
|| DEFAULT_UI_LANGUAGE;
|
||||
}
|
||||
|
||||
function setUserLanguage(lang, callback) {
|
||||
setPermanentGlobalCookie('userlang', lang);
|
||||
window.localStorage.setItem('userlang', lang);
|
||||
Translations.load(lang);
|
||||
Translations.whenReady(callback);
|
||||
}
|
||||
|
@ -549,7 +549,3 @@ function finishViewerSetupOnceTranslationsAreLoaded()
|
||||
|
||||
viewerSetupComplete = true;
|
||||
}
|
||||
|
||||
function setPermanentGlobalCookie(name, value) {
|
||||
document.cookie = `${name}=${value};path=${root};max-age=31536000`;
|
||||
}
|
||||
|
Reference in New Issue
Block a user