mirror of https://github.com/kiwix/libkiwix.git
UI language setting is preserved in a cookie
This commit is contained in:
parent
d59cfb1fa2
commit
a620c8658b
|
@ -69,6 +69,17 @@ 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';
|
const DEFAULT_UI_LANGUAGE = 'en';
|
||||||
|
|
||||||
|
@ -76,10 +87,13 @@ Translations.load(DEFAULT_UI_LANGUAGE, /*asDefault=*/true);
|
||||||
|
|
||||||
function getUserLanguage() {
|
function getUserLanguage() {
|
||||||
return new URLSearchParams(window.location.search).get('userlang')
|
return new URLSearchParams(window.location.search).get('userlang')
|
||||||
|
|| getCookie('userlang')
|
||||||
|| DEFAULT_UI_LANGUAGE;
|
|| DEFAULT_UI_LANGUAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUserLanguage(lang, callback) {
|
function setUserLanguage(lang, callback) {
|
||||||
|
const rootPath = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
|
||||||
|
document.cookie = `userlang=${lang};path=${rootPath};max-age=31536000`;
|
||||||
Translations.load(lang);
|
Translations.load(lang);
|
||||||
Translations.whenReady(callback);
|
Translations.whenReady(callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ const ResourceCollection resources200Compressible{
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/favicon/favicon.ico" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/favicon/favicon.ico" },
|
||||||
{ STATIC_CONTENT, "/ROOT/skin/favicon/favicon.ico?cacheid=fba03a27" },
|
{ STATIC_CONTENT, "/ROOT/skin/favicon/favicon.ico?cacheid=fba03a27" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/i18n.js" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/i18n.js" },
|
||||||
{ STATIC_CONTENT, "/ROOT/skin/i18n.js?cacheid=eb41f5ce" },
|
{ STATIC_CONTENT, "/ROOT/skin/i18n.js?cacheid=dcf3d584" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/index.css" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/index.css" },
|
||||||
{ STATIC_CONTENT, "/ROOT/skin/index.css?cacheid=0f9ba34e" },
|
{ STATIC_CONTENT, "/ROOT/skin/index.css?cacheid=0f9ba34e" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/index.js" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/index.js" },
|
||||||
|
@ -300,7 +300,7 @@ R"EXPECTEDRESULT( <img src="../skin/download.png?
|
||||||
/* url */ "/ROOT/viewer",
|
/* url */ "/ROOT/viewer",
|
||||||
R"EXPECTEDRESULT( <link type="text/css" href="./skin/taskbar.css?cacheid=2cbac34b" rel="Stylesheet" />
|
R"EXPECTEDRESULT( <link type="text/css" href="./skin/taskbar.css?cacheid=2cbac34b" rel="Stylesheet" />
|
||||||
<link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" />
|
<link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" />
|
||||||
<script type="module" src="./skin/i18n.js?cacheid=eb41f5ce" defer></script>
|
<script type="module" src="./skin/i18n.js?cacheid=dcf3d584" defer></script>
|
||||||
<script type="text/javascript" src="./skin/languages.js?cacheid=fe100348" defer></script>
|
<script type="text/javascript" src="./skin/languages.js?cacheid=fe100348" defer></script>
|
||||||
<script type="text/javascript" src="./skin/viewer.js?cacheid=b3c754ec" defer></script>
|
<script type="text/javascript" src="./skin/viewer.js?cacheid=b3c754ec" defer></script>
|
||||||
<script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script>
|
<script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script>
|
||||||
|
|
Loading…
Reference in New Issue