From 6c2f229d310ec610721f0647bbe4457c3fd51d55 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 20 Jan 2023 18:06:57 +0400 Subject: [PATCH] Added prototype UI language selector Known issues - styling / placement - language changes via the selector UI are not recorded in the navigation history - changing the language via the UI doesn't update the `?userlang=` URL query parameter --- static/skin/taskbar.css | 4 ++++ static/skin/viewer.js | 20 ++++++++++++++++++++ static/viewer.html | 2 ++ test/server.cpp | 8 ++++---- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/static/skin/taskbar.css b/static/skin/taskbar.css index ad8ceb0a5..332bd2444 100644 --- a/static/skin/taskbar.css +++ b/static/skin/taskbar.css @@ -44,6 +44,10 @@ margin: 0 auto; } +#ui_language { + float: left +} + #kiwix_button_show_toggle { display: none; } diff --git a/static/skin/viewer.js b/static/skin/viewer.js index 94546f916..b73150950 100644 --- a/static/skin/viewer.js +++ b/static/skin/viewer.js @@ -403,6 +403,25 @@ function setupSuggestions() { }); } +function initUILanguageSelector() { + const languageSelector = document.getElementById("ui_language"); + for (const lang of uiLanguages ) { + const lang_name = Object.getOwnPropertyNames(lang)[0]; + const lang_code = lang[lang_name]; + const is_selected = lang_code == viewerState.uiLanguage; + languageSelector.appendChild(new Option(lang_name, lang_code, is_selected, is_selected)); + } +} + +function changeUILanguage() { + const s = document.getElementById("ui_language"); + const lang = s.options[s.selectedIndex].value; + viewerState.uiLanguage = lang; + setUserLanguage(lang, () => { + updateUIText(); + }); +} + function setupViewer() { // Defer the call of handle_visual_viewport_change() until after the // presence or absence of the taskbar as determined by this function @@ -425,6 +444,7 @@ function setupViewer() { document.getElementById("kiwix_serve_taskbar_library_button").remove(); } + initUILanguageSelector(); setupSuggestions(); // cybook hack diff --git a/static/viewer.html b/static/viewer.html index 89b8cf84e..1eba63657 100644 --- a/static/viewer.html +++ b/static/viewer.html @@ -29,6 +29,8 @@