WebUI: Allow to specify login page language via query parameter

There were a few reports that the user has messed up their browser's language and this PR gives an escape hatch in case the user is unable to configure the browser's language for various reasons.
Example for choosing French: http://127.0.0.1:8080/?lang=fr

PR #20591.
This commit is contained in:
Chocobo1 2024-04-06 15:13:58 +08:00 committed by GitHub
parent 67dfce7437
commit 92ce507151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,6 +31,16 @@
async function setupI18n() {
const languages = (() => {
const langs = new Set();
// list of available languages: https://github.com/qbittorrent/qBittorrent/tree/master/src/webui/www/public/lang
const queryLang = new URLSearchParams(window.location.search).get('lang');
if (queryLang !== null) {
// use the fallback lang if `queryLang` is present but empty
// limit the length of the language string to prevent Client-side Request Forgery
if ((queryLang.length > 0) && (queryLang.length <= 8))
langs.add(queryLang.replace('-', '_'));
}
else {
for (const lang of navigator.languages) {
langs.add(lang.replace('-', '_'));
@ -38,6 +48,8 @@ async function setupI18n() {
if (idx > 0)
langs.add(lang.slice(0, idx));
}
}
langs.add('en'); // fallback
return Array.from(langs);
})();