Fixed userlang control in the viewer

Now the viewer stores the userlang preference in window.localStorage.
This commit is contained in:
Veloman Yunkan
2023-09-09 19:14:39 +04:00
parent f8c3a1fd2e
commit 9063450b5a
3 changed files with 8 additions and 23 deletions

View File

@ -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);
}

View File

@ -549,7 +549,3 @@ function finishViewerSetupOnceTranslationsAreLoaded()
viewerSetupComplete = true;
}
function setPermanentGlobalCookie(name, value) {
document.cookie = `${name}=${value};path=${root};max-age=31536000`;
}