1
mirror of https://github.com/qbittorrent/qBittorrent synced 2024-11-10 01:54:44 +01:00

Revert "Use client side translation for public login page"

This reverts #20520.
PR #21290.
This commit is contained in:
Chocobo1 2024-09-06 15:38:31 +08:00 committed by GitHub
parent 0e63b83aed
commit 944499814b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
66 changed files with 12 additions and 802 deletions

View File

@ -78,11 +78,7 @@ repos:
m4/.* | m4/.* |
src/base/3rdparty/.* | src/base/3rdparty/.* |
src/searchengine/nova3/socks.py | src/searchengine/nova3/socks.py |
src/webui/www/private/lang/.* | src/webui/www/private/scripts/lib/.*
src/webui/www/private/scripts/lib/.* |
src/webui/www/public/lang/.* |
src/webui/www/public/scripts/lib/.* |
src/webui/www/transifex/.*
)$ )$
exclude_types: exclude_types:
- ts - ts
@ -106,11 +102,7 @@ repos:
m4/.* | m4/.* |
src/base/3rdparty/.* | src/base/3rdparty/.* |
src/searchengine/nova3/socks.py | src/searchengine/nova3/socks.py |
src/webui/www/private/lang/.* | src/webui/www/private/scripts/lib/.*
src/webui/www/private/scripts/lib/.* |
src/webui/www/public/lang/.* |
src/webui/www/public/scripts/lib/.* |
src/webui/www/transifex/.*
)$ )$
exclude_types: exclude_types:
- svg - svg

View File

@ -17,14 +17,6 @@ type = QT
minimum_perc = 23 minimum_perc = 23
lang_map = pt: pt_PT, zh: zh_CN lang_map = pt: pt_PT, zh: zh_CN
[o:sledgehammer999:p:qbittorrent:r:qbittorrent_webui_json]
file_filter = src/webui/www/transifex/<lang>.json
source_file = src/webui/www/transifex/en.json
source_lang = en
type = KEYVALUEJSON
minimum_perc = 23
lang_map = pt: pt_PT, zh: zh_CN
[o:sledgehammer999:p:qbittorrent:r:qbittorrentdesktop_master] [o:sledgehammer999:p:qbittorrent:r:qbittorrentdesktop_master]
source_file = dist/unix/org.qbittorrent.qBittorrent.desktop source_file = dist/unix/org.qbittorrent.qBittorrent.desktop
source_lang = en source_lang = en

View File

@ -6,7 +6,6 @@
"url": "https://github.com/qbittorrent/qBittorrent.git" "url": "https://github.com/qbittorrent/qBittorrent.git"
}, },
"scripts": { "scripts": {
"extract_translation": "i18next -c public/i18next-parser.config.mjs public/index.html public/scripts/login.js",
"format": "js-beautify -r *.mjs private/*.html private/scripts/*.js private/views/*.html public/*.html public/scripts/*.js && prettier --write **.css", "format": "js-beautify -r *.mjs private/*.html private/scripts/*.js private/views/*.html public/*.html public/scripts/*.js && prettier --write **.css",
"lint": "eslint *.mjs private/*.html private/scripts/*.js private/views/*.html public/*.html public/scripts/*.js && stylelint **/*.css && html-validate private public" "lint": "eslint *.mjs private/*.html private/scripts/*.js private/views/*.html public/*.html public/scripts/*.js && stylelint **/*.css && html-validate private public"
}, },
@ -16,7 +15,6 @@
"eslint-plugin-html": "*", "eslint-plugin-html": "*",
"eslint-plugin-regexp": "*", "eslint-plugin-regexp": "*",
"html-validate": "*", "html-validate": "*",
"i18next-parser": "*",
"js-beautify": "*", "js-beautify": "*",
"prettier": "*", "prettier": "*",
"stylelint": "*", "stylelint": "*",

View File

@ -1,10 +0,0 @@
export default {
createOldCatalogs: false,
failOnWarnings: true,
keySeparator: false,
lineEnding: 'lf',
locales: ['en'],
namespaceSeparator: false,
output: 'public/lang/$LOCALE.json',
sort: true
}

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="${LANG}">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -7,7 +7,7 @@
<meta name="description" content="qBittorrent WebUI"> <meta name="description" content="qBittorrent WebUI">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>qBittorrent WebUI</title> <title>QBT_TR(qBittorrent WebUI)QBT_TR[CONTEXT=Login]</title>
<link rel="icon" type="image/png" href="images/qbittorrent32.png"> <link rel="icon" type="image/png" href="images/qbittorrent32.png">
<link rel="icon" type="image/svg+xml" href="images/qbittorrent-tray.svg"> <link rel="icon" type="image/svg+xml" href="images/qbittorrent-tray.svg">
@ -16,31 +16,30 @@
<link rel="stylesheet" type="text/css" href="css/noscript.css?v=${CACHEID}"> <link rel="stylesheet" type="text/css" href="css/noscript.css?v=${CACHEID}">
</noscript> </noscript>
<script defer src="scripts/lib/i18next.min.js"></script> <script defer src="scripts/login.js?locale=${LANG}&v=${CACHEID}"></script>
<script defer src="scripts/login.js?v=${CACHEID}"></script>
</head> </head>
<body> <body>
<noscript id="noscript"> <noscript id="noscript">
<h1>JavaScript Required! You must enable JavaScript for the WebUI to work properly</h1> <h1>QBT_TR(JavaScript Required! You must enable JavaScript for the WebUI to work properly)QBT_TR[CONTEXT=Login]</h1>
</noscript> </noscript>
<div id="main"> <div id="main">
<h1>qBittorrent WebUI</h1> <h1>QBT_TR(qBittorrent WebUI)QBT_TR[CONTEXT=Login]</h1>
<div id="logo" class="col"> <div id="logo" class="col">
<img src="images/qbittorrent-tray.svg" alt="qBittorrent logo"> <img src="images/qbittorrent-tray.svg" alt="qBittorrent logo">
</div> </div>
<div id="formplace" class="col"> <div id="formplace" class="col">
<form id="loginform"> <form id="loginform">
<div class="row"> <div class="row">
<label for="username" class="qbt-translatable" data-i18n="Username">Username</label><br> <label for="username">QBT_TR(Username)QBT_TR[CONTEXT=Login]</label><br>
<input type="text" id="username" name="username" autocomplete="username" autofocus required> <input type="text" id="username" name="username" autocomplete="username" autofocus required>
</div> </div>
<div class="row"> <div class="row">
<label for="password" class="qbt-translatable" data-i18n="Password">Password</label><br> <label for="password">QBT_TR(Password)QBT_TR[CONTEXT=Login]</label><br>
<input type="password" id="password" name="password" autocomplete="current-password" required> <input type="password" id="password" name="password" autocomplete="current-password" required>
</div> </div>
<div class="row"> <div class="row">
<input type="submit" id="loginButton" class="qbt-translatable" data-i18n="Login" value="Login"> <input type="submit" id="loginButton" value="QBT_TR(Login)QBT_TR[CONTEXT=Login]">
</div> </div>
</form> </form>
</div> </div>

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "اسم المستخدم أو كلمة السر غير صالحة.",
"Login": "ولوج",
"Password": "كلمة السر",
"Unable to log in, server is probably unreachable.": "",
"Username": "اسم المستخدم"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "İstifadəçi adı və Şifrə səhvdir.",
"Login": "Giriş",
"Password": "Şifrə",
"Unable to log in, server is probably unreachable.": "",
"Username": "İstifadəçi adı"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Нядзейсныя імя карыстальніка ці пароль.",
"Login": "Логін",
"Password": "Пароль",
"Unable to log in, server is probably unreachable.": "",
"Username": "Імя карыстальніка"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Невалидно потребителско име или парола.",
"Login": "Вход",
"Password": "Парола",
"Unable to log in, server is probably unreachable.": "",
"Username": "Потребителско име"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nom d'usuari o contrasenya incorrectes.",
"Login": "Inicia sessió",
"Password": "Contrasenya",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nom d'usuari"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Neplatné jméno nebo heslo",
"Login": "Přihlášení",
"Password": "Heslo",
"Unable to log in, server is probably unreachable.": "",
"Username": "Uživatelské jméno"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Ugyldigt brugernavn eller adgangskode.",
"Login": "Login",
"Password": "Adgangskode",
"Unable to log in, server is probably unreachable.": "",
"Username": "Brugernavn"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Ungültiger Benutzername oder Passwort.",
"Login": "Anmelden",
"Password": "Passwort",
"Unable to log in, server is probably unreachable.": "",
"Username": "Benutzername"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Μη έγκυρο Όνομα Χρήστη ή Κωδικός Πρόσβασης.",
"Login": "Σύνδεση",
"Password": "Κωδικός Πρόσβασης",
"Unable to log in, server is probably unreachable.": "",
"Username": "Όνομα χρήστη"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Invalid Username or Password.",
"Login": "Login",
"Password": "Password",
"Unable to log in, server is probably unreachable.": "Unable to log in, server is probably unreachable.",
"Username": "Username"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Invalid Username or Password.",
"Login": "Login",
"Password": "Password",
"Unable to log in, server is probably unreachable.": "",
"Username": "Username"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "",
"Login": "Login",
"Password": "",
"Unable to log in, server is probably unreachable.": "",
"Username": ""
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Malvalida uzantnomo aŭ pasvorto.",
"Login": "Ensaluti",
"Password": "Pasvorto",
"Unable to log in, server is probably unreachable.": "",
"Username": ""
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nombre de usuario o contraseña inválidos.",
"Login": "Iniciar sesión",
"Password": "Contraseña",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nombre de usuario"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Sobimatu Kasutajanimi või Parool",
"Login": "Logi sisse",
"Password": "Parool",
"Unable to log in, server is probably unreachable.": "",
"Username": "Kasutajanimi"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Erabiltzaile-izen edo Sarhitz baliogabea.",
"Login": "Hasi Saioa",
"Password": "Sarhitza",
"Unable to log in, server is probably unreachable.": "",
"Username": "Erabiltzaile-izena"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "نام کاربری یا کلمه عبور نامعتبر",
"Login": "ورود",
"Password": "کلمه عبور",
"Unable to log in, server is probably unreachable.": "",
"Username": "نام کاربری"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Virheellinen käyttäjätunnus tai salasana.",
"Login": "Kirjaudu",
"Password": "Salasana",
"Unable to log in, server is probably unreachable.": "",
"Username": "Käyttäjänimi"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nom d'utilisateur ou mot de passe invalide.",
"Login": "Se connecter",
"Password": "Mot de passe",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nom d'utilisateur"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "O usuario ou o contrasinal son incorrectos.",
"Login": "Iniciar sesión",
"Password": "Contrasinal",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nome do usuario"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "שם משתמש או סיסמה בלתי תקפים.",
"Login": "היכנס",
"Password": "סיסמה",
"Unable to log in, server is probably unreachable.": "",
"Username": "שם משתמש"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "यूजरनेम व पासवर्ड अमान्य हैं।",
"Login": "लॉगिन",
"Password": "पासवर्ड",
"Unable to log in, server is probably unreachable.": "",
"Username": "यूजरनेम"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Neispravno korisničko ime ili lozinka",
"Login": "Prijava",
"Password": "Lozinka",
"Unable to log in, server is probably unreachable.": "",
"Username": "Korisničko ime"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Érvénytelen felhasználónév vagy Jelszó.",
"Login": "Bejelentkezés",
"Password": "Jelszó",
"Unable to log in, server is probably unreachable.": "",
"Username": "Felhasználónév"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "",
"Login": "Օգտանուն",
"Password": "Գաղտնաբառ",
"Unable to log in, server is probably unreachable.": "",
"Username": "Մուտքանուն"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nama Pengguna atau Sandi tidak valid.",
"Login": "Masuk",
"Password": "Sandi",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nama pengguna"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Rangt notandanafn eða lykilorð.",
"Login": "Skrá inn",
"Password": "Lykilorð",
"Unable to log in, server is probably unreachable.": "",
"Username": ""
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Username o password errati.",
"Login": "Login",
"Password": "Password",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nome utente"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "ユーザー名またはパスワーが正しくありません。",
"Login": "ログイン",
"Password": "パスワード",
"Unable to log in, server is probably unreachable.": "",
"Username": "ユーザー名"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "არასწორი მომხმარებლის სახელი ან პაროლი.",
"Login": "შესვლა",
"Password": "პაროლი",
"Unable to log in, server is probably unreachable.": "",
"Username": "მომხმარებლის სახელი"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "사용자 이름/암호가 올바르지 않습니다.",
"Login": "로그인",
"Password": "암호",
"Unable to log in, server is probably unreachable.": "",
"Username": "사용자 이름"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Neteisingas naudotojo vardas ar slaptažodis.",
"Login": "Prisijungimas",
"Password": "Slaptažodis",
"Unable to log in, server is probably unreachable.": "",
"Username": "Naudotojo vardas"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Napareizs slāgvuords voi paroļs",
"Login": "Dasaslāgt",
"Password": "Paroļs",
"Unable to log in, server is probably unreachable.": "",
"Username": "Lītuotuojs"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nederīgs lietotājvārds vai parole.",
"Login": "Pierakstīties",
"Password": "Parole",
"Unable to log in, server is probably unreachable.": "",
"Username": "Lietotājvārds"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Хэрэглэгчийн нэр эсвэл нууц үг тохирохгүй байна.",
"Login": "Нэвтрэх",
"Password": "Нууц үг",
"Unable to log in, server is probably unreachable.": "",
"Username": "Хэрэглэгчийн нэр"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nama Pengguna atau Kata Laluan tidak sah.",
"Login": "Daftar Masuk",
"Password": "Kata Laluan",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nama pengguna"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Ugyldig brukernavn eller passord.",
"Login": "Logg inn",
"Password": "Passord",
"Unable to log in, server is probably unreachable.": "",
"Username": "Brukernavn"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Ongeldige gebruikersnaam of wachtwoord.",
"Login": "Login",
"Password": "Wachtwoord",
"Unable to log in, server is probably unreachable.": "",
"Username": "Gebruikersnaam"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nom d'utilizaire o senhal invalid.",
"Login": "Identificant",
"Password": "Senhal",
"Unable to log in, server is probably unreachable.": "",
"Username": ""
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nieprawidłowa nazwa użytkownika lub hasło.",
"Login": "Login",
"Password": "Hasło",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nazwa użytkownika"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nome de usuário ou senha inválidos.",
"Login": "Login",
"Password": "Senha",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nome de usuário"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Palavra-passe ou nome de utilizador inválido.",
"Login": "Iniciar sessão",
"Password": "Palavra-passe",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nome de utilizador"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Numele de utilizator sau parola nu sunt valide.",
"Login": "Autentifică",
"Password": "Parolă",
"Unable to log in, server is probably unreachable.": "",
"Username": "Nume de utilizator"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Неверное имя пользователя или пароль.",
"Login": "Войти",
"Password": "Пароль",
"Unable to log in, server is probably unreachable.": "",
"Username": "Имя пользователя"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Nesprávne užívateľské meno alebo heslo.",
"Login": "Prihlasovacie meno",
"Password": "Heslo",
"Unable to log in, server is probably unreachable.": "",
"Username": "Meno používateľa"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Neveljavno uporabniško ime ali geslo.",
"Login": "Prijava",
"Password": "Geslo",
"Unable to log in, server is probably unreachable.": "",
"Username": "Uporabniško ime"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Неважеће корисничко име или шифра.",
"Login": "Логовање",
"Password": "Шифра",
"Unable to log in, server is probably unreachable.": "",
"Username": "Корисничко име"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Felaktigt användarnamn eller lösenord.",
"Login": "Inloggning",
"Password": "Lösenord",
"Unable to log in, server is probably unreachable.": "",
"Username": "Användarnamn"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง.",
"Login": "ล็อกอิน",
"Password": "รหัสผ่าน",
"Unable to log in, server is probably unreachable.": "",
"Username": "ชื่อผู้ใช้"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Geçersiz Kullanıcı Adı veya Parola.",
"Login": "Oturum Aç",
"Password": "Parola",
"Unable to log in, server is probably unreachable.": "",
"Username": "Kullanıcı adı"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Неправильний логін або пароль.",
"Login": "Логін",
"Password": "Пароль",
"Unable to log in, server is probably unreachable.": "",
"Username": "Ім'я користувача"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Foydalanuvchi ismi yoki parol notogri.",
"Login": "Kirish",
"Password": "Parol",
"Unable to log in, server is probably unreachable.": "",
"Username": ""
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "Tên tài khoản hoặc Mật khẩu không hợp lệ",
"Login": "Đăng nhập",
"Password": "Mật khẩu",
"Unable to log in, server is probably unreachable.": "",
"Username": "Tên tài khoản"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "无效的用户名或密码。",
"Login": "登录",
"Password": "密码",
"Unable to log in, server is probably unreachable.": "",
"Username": "用户名"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "無效用戶名稱或密碼。",
"Login": "登入",
"Password": "密碼",
"Unable to log in, server is probably unreachable.": "",
"Username": "用戶名"
}

View File

@ -1,7 +0,0 @@
{
"Invalid Username or Password.": "無效的使用者名稱或密碼。",
"Login": "登入",
"Password": "密碼",
"Unable to log in, server is probably unreachable.": "",
"Username": "使用者名稱"
}

File diff suppressed because one or more lines are too long

View File

@ -28,77 +28,6 @@
"use strict"; "use strict";
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("-", "_"));
const idx = lang.indexOf("-");
if (idx > 0)
langs.add(lang.slice(0, idx));
}
}
langs.add("en"); // fallback
return Array.from(langs);
})();
// it is faster to fetch all translation files at once than one by one
const fetches = languages.map(lang => fetch(`lang/${lang}.json`));
const fetchResults = await Promise.allSettled(fetches);
const translations = fetchResults
.map((value, idx) => ({ lang: languages[idx], result: value }))
.filter(v => (v.result.value.status === 200));
const translation = {
lang: (translations.length > 0) ? translations[0].lang.replace("_", "-") : undefined,
data: (translations.length > 0) ? (await translations[0].result.value.json()) : {}
};
// present it to i18next
const i18nextOptions = {
lng: translation.lang,
fallbackLng: false,
load: "currentOnly",
resources: {
[translation.lang]: { translation: translation.data }
},
returnEmptyString: false
};
i18next.init(i18nextOptions, replaceI18nText);
}
function replaceI18nText() {
const tr = i18next.t; // workaround for warnings from i18next-parser
for (const element of document.getElementsByClassName("qbt-translatable")) {
const translationKey = element.getAttribute("data-i18n");
const translatedValue = tr(translationKey);
switch (element.nodeName) {
case "INPUT":
element.value = translatedValue;
break;
case "LABEL":
element.textContent = translatedValue;
break;
default:
console.error(`Unhandled element: ${element}`);
break;
}
}
document.documentElement.lang = i18next.language.split("-")[0];
}
function submitLoginForm(event) { function submitLoginForm(event) {
event.preventDefault(); event.preventDefault();
const errorMsgElement = document.getElementById("error_msg"); const errorMsgElement = document.getElementById("error_msg");
@ -111,13 +40,13 @@ function submitLoginForm(event) {
if ((xhr.status === 200) && (xhr.responseText === "Ok.")) if ((xhr.status === 200) && (xhr.responseText === "Ok."))
location.replace(location); location.replace(location);
else else
errorMsgElement.textContent = i18next.t("Invalid Username or Password."); errorMsgElement.textContent = "QBT_TR(Invalid Username or Password.)QBT_TR[CONTEXT=Login]";
} }
}); });
xhr.addEventListener("error", () => { xhr.addEventListener("error", () => {
errorMsgElement.textContent = (xhr.responseText !== "") errorMsgElement.textContent = (xhr.responseText !== "")
? xhr.responseText ? xhr.responseText
: i18next.t("Unable to log in, server is probably unreachable."); : "QBT_TR(Unable to log in, server is probably unreachable.)QBT_TR[CONTEXT=Login]";
}); });
const usernameElement = document.getElementById("username"); const usernameElement = document.getElementById("username");
@ -133,6 +62,4 @@ document.addEventListener("DOMContentLoaded", () => {
const loginForm = document.getElementById("loginform"); const loginForm = document.getElementById("loginform");
loginForm.method = "POST"; loginForm.method = "POST";
loginForm.addEventListener("submit", submitLoginForm); loginForm.addEventListener("submit", submitLoginForm);
setupI18n();
}); });

View File

@ -1,133 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# split_merge_json.py - script for splitting the JSON files from
# Transifex into their public/private parts and to merging the
# private/public en.json files to form the source file for Transifex
#
# Copyright (C) 2024 sledgehammer999 <hammered999@gmail.com>
#
# License: Public domain.
import argparse
import glob
import json
import os
from pathlib import PurePath
import sys
def updateJson(json_file: str, source: dict[str, str]) -> None:
trimmed_path: str = json_file
path_parts = PurePath(json_file).parts
if len(path_parts) >= 3:
trimmed_path = f"{path_parts[-3]}/{path_parts[-2]}/{path_parts[-1]}"
if not os.path.exists(json_file):
print(f"\tWARNIG: {trimmed_path} doesn't exist")
return
print(f"\tUpdating {trimmed_path}")
with open(json_file, mode="r+", encoding='utf-8') as file:
target: dict[str, str] = json.load(file)
if not isinstance(target, dict):
print(f"\tWARNIG: {trimmed_path} is malormed")
return
for key in target.keys():
value = source.get(key)
if value:
target[key] = value
file.seek(0)
json.dump(target, file, ensure_ascii=False, indent=2, sort_keys=True)
file.write("\n")
file.truncate()
def splitJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
locales: list[str] = glob.glob("*.json", root_dir=transifex_dir)
locales = [x for x in locales if x != "en.json"]
for locale in locales:
print(f"Processing lang {locale}")
transifex_file: str = f"{transifex_dir}/{locale}"
public_file: str = f"{json_public_dir}/{locale}"
private_file: str = f"{json_private_dir}/{locale}"
transifex_json: dict[str, str] = {}
with open(transifex_file, mode="r", encoding='utf-8') as file:
transifex_json = json.load(file)
if not isinstance(transifex_json, dict):
trimmed_path: str = transifex_file
path_parts = PurePath(transifex_file).parts
if len(path_parts) >= 2:
trimmed_path = f"{path_parts[-2]}/{path_parts[-1]}"
print(f"\tERROR: {trimmed_path} is malformed.")
continue
updateJson(public_file, transifex_json)
updateJson(private_file, transifex_json)
def mergeJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
transifex_en_file: str = f"{transifex_dir}/en.json"
public_en_file: str = f"{json_public_dir}/en.json"
private_en_file: str = f"{json_private_dir}/en.json"
transifex_en_json: dict[str, str] = {}
public_en_json: dict[str, str] = {}
private_en_json: dict[str, str] = {}
print("Merging source en.json file")
if os.path.exists(public_en_file):
with open(public_en_file, mode="r", encoding='utf-8') as file:
public_en_json = json.load(file)
if not isinstance(public_en_json, dict):
public_en_json = {}
if os.path.exists(private_en_file):
with open(private_en_file, mode="r", encoding='utf-8') as file:
private_en_json = json.load(file)
if not isinstance(private_en_json, dict):
private_en_json = {}
transifex_en_json = public_en_json | private_en_json
with open(transifex_en_file, mode="w", encoding='utf-8') as file:
json.dump(transifex_en_json, file, ensure_ascii=False, indent=2, sort_keys=True)
file.write("\n")
def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
transifex_dir: str = f"{script_path}/transifex"
json_public_dir: str = f"{script_path}/public/lang"
json_private_dir: str = f"{script_path}/private/lang"
parser = argparse.ArgumentParser()
parser.add_argument("--mode", required=True, choices=["split", "merge"], help="SPLIT the translations files from Transifex into their public/private JSON counterpart. MERGE to merge the public and private en.json files into the 'transifex/en.json' file")
parser.add_argument("--transifex-dir", default=transifex_dir, nargs=1, help=f"directory of WebUI transifex file (default: '{transifex_dir}')")
parser.add_argument("--json-public-dir", default=json_public_dir, nargs=1, help=f"directory of WebUI public JSON translation files(default: '{json_public_dir}')")
parser.add_argument("--json-private-dir", default=json_private_dir, nargs=1, help=f"directory of WebUI private JSON translation files(default: '{json_private_dir}')")
args = parser.parse_args()
if not os.path.isdir(args.transifex_dir):
raise RuntimeError(f"'{args.transifex_dir}' isn't a directory")
if not os.path.isdir(args.json_public_dir):
raise RuntimeError(f"'{args.json_public_dir}' isn't a directory")
if not os.path.isdir(args.json_private_dir):
raise RuntimeError(f"'{args.json_private_dir}' isn't a directory")
if args.mode == "merge":
mergeJson(transifex_dir, json_public_dir, json_private_dir)
else:
splitJson(transifex_dir, json_public_dir, json_private_dir)
print("Done.")
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,105 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# translations_qt2i18next.py - script for migrating translations from Qt's .ts files
# to i18next compatible JSON files.
# Copyright (C) 2024 sledgehammer999 <hammered999@gmail.com>
#
# License: Public domain.
import argparse
import glob
import json
import os
import sys
import xml.etree.ElementTree as ET
def getTsStrings(ts_file: str, key: str) -> list[str]:
tr_strings: list[str] = []
tree = ET.parse(ts_file)
root = tree.getroot()
for context in root.findall('context'):
for message in context.findall('message'):
source = message.find('source').text
if key != source:
continue
translation = message.find('translation').text
if not translation:
continue
if translation not in tr_strings:
tr_strings.append(translation)
return tr_strings
def migrate2Json(ts_dir: str, json_dir: str, locale: str) -> None:
ts_file: str = f"{ts_dir}/webui_{locale}.ts"
js_file: str = f"{json_dir}/{locale}.json"
print(f"Processing lang {locale}")
if not os.path.exists(ts_file):
print(f"\tERROR: {ts_file} doesn't exist.")
return
with open(js_file, mode="r+", encoding='utf-8') as file:
translations = json.load(file)
if not isinstance(translations, dict):
print(f"\tERROR: {js_file} is malformed.")
return
for key, value in translations.items():
if not (isinstance(key, str) and isinstance(value, str) and not value):
continue
ts_strings: list[str] = getTsStrings(ts_file, key)
ts_len: int = len(ts_strings)
if ts_len == 0:
print(f"\tWARNING: Translation for '{key}' not found.")
continue
if ts_len > 1:
print(f"\tWARNING: Multiple translations for '{key}' found.")
continue
translations[key] = ts_strings[0]
file.seek(0)
json.dump(translations, file, ensure_ascii=False, indent=2, sort_keys=True)
file.write("\n")
file.truncate()
print("\tFinished.")
def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
ts_dir: str = f"{script_path}/translations"
json_dir: str = f"{script_path}/public/lang"
parser = argparse.ArgumentParser()
parser.add_argument("--ts-dir", default=ts_dir, nargs=1, help=f"directory of WebUI .ts translation files (default: '{ts_dir}')")
parser.add_argument("--json-dir", default=json_dir, nargs=1, help=f"directory of WebUI .json translation files(default: '{json_dir}')")
args = parser.parse_args()
if not os.path.isdir(args.ts_dir):
raise RuntimeError(f"'{args.ts_dir}' isn't a directory")
if not os.path.isdir(args.json_dir):
raise RuntimeError(f"'{args.json_dir}' isn't a directory")
locales: list[str] = glob.glob("*.json", root_dir=json_dir)
locales = [x.removesuffix(".json") for x in locales if x != "en.json"]
for locale in locales:
migrate2Json(ts_dir, json_dir, locale)
print("Done.")
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -439,63 +439,6 @@
<file>public/images/qbittorrent-tray.svg</file> <file>public/images/qbittorrent-tray.svg</file>
<file>public/images/qbittorrent32.png</file> <file>public/images/qbittorrent32.png</file>
<file>public/index.html</file> <file>public/index.html</file>
<file>public/lang/ar.json</file>
<file>public/lang/az@latin.json</file>
<file>public/lang/be.json</file>
<file>public/lang/bg.json</file>
<file>public/lang/ca.json</file>
<file>public/lang/cs.json</file>
<file>public/lang/da.json</file>
<file>public/lang/de.json</file>
<file>public/lang/el.json</file>
<file>public/lang/en.json</file>
<file>public/lang/en_AU.json</file>
<file>public/lang/en_GB.json</file>
<file>public/lang/eo.json</file>
<file>public/lang/es.json</file>
<file>public/lang/et.json</file>
<file>public/lang/eu.json</file>
<file>public/lang/fa.json</file>
<file>public/lang/fi.json</file>
<file>public/lang/fr.json</file>
<file>public/lang/gl.json</file>
<file>public/lang/he.json</file>
<file>public/lang/hi_IN.json</file>
<file>public/lang/hr.json</file>
<file>public/lang/hu.json</file>
<file>public/lang/hy.json</file>
<file>public/lang/id.json</file>
<file>public/lang/is.json</file>
<file>public/lang/it.json</file>
<file>public/lang/ja.json</file>
<file>public/lang/ka.json</file>
<file>public/lang/ko.json</file>
<file>public/lang/lt.json</file>
<file>public/lang/ltg.json</file>
<file>public/lang/lv_LV.json</file>
<file>public/lang/mn_MN.json</file>
<file>public/lang/ms_MY.json</file>
<file>public/lang/nb.json</file>
<file>public/lang/nl.json</file>
<file>public/lang/oc.json</file>
<file>public/lang/pl.json</file>
<file>public/lang/pt_BR.json</file>
<file>public/lang/pt_PT.json</file>
<file>public/lang/ro.json</file>
<file>public/lang/ru.json</file>
<file>public/lang/sk.json</file>
<file>public/lang/sl.json</file>
<file>public/lang/sr.json</file>
<file>public/lang/sv.json</file>
<file>public/lang/th.json</file>
<file>public/lang/tr.json</file>
<file>public/lang/uk.json</file>
<file>public/lang/uz@Latn.json</file>
<file>public/lang/vi.json</file>
<file>public/lang/zh_CN.json</file>
<file>public/lang/zh_HK.json</file>
<file>public/lang/zh_TW.json</file>
<file>public/scripts/lib/i18next.min.js</file>
<file>public/scripts/login.js</file> <file>public/scripts/login.js</file>
</qresource> </qresource>
</RCC> </RCC>