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
66 changed files with 12 additions and 802 deletions

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>
<html lang="en">
<html lang="${LANG}">
<head>
<meta charset="UTF-8">
@@ -7,7 +7,7 @@
<meta name="description" content="qBittorrent WebUI">
<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/svg+xml" href="images/qbittorrent-tray.svg">
@@ -16,31 +16,30 @@
<link rel="stylesheet" type="text/css" href="css/noscript.css?v=${CACHEID}">
</noscript>
<script defer src="scripts/lib/i18next.min.js"></script>
<script defer src="scripts/login.js?v=${CACHEID}"></script>
<script defer src="scripts/login.js?locale=${LANG}&v=${CACHEID}"></script>
</head>
<body>
<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>
<div id="main">
<h1>qBittorrent WebUI</h1>
<h1>QBT_TR(qBittorrent WebUI)QBT_TR[CONTEXT=Login]</h1>
<div id="logo" class="col">
<img src="images/qbittorrent-tray.svg" alt="qBittorrent logo">
</div>
<div id="formplace" class="col">
<form id="loginform">
<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>
</div>
<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>
</div>
<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>
</form>
</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";
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) {
event.preventDefault();
const errorMsgElement = document.getElementById("error_msg");
@@ -111,13 +40,13 @@ function submitLoginForm(event) {
if ((xhr.status === 200) && (xhr.responseText === "Ok."))
location.replace(location);
else
errorMsgElement.textContent = i18next.t("Invalid Username or Password.");
errorMsgElement.textContent = "QBT_TR(Invalid Username or Password.)QBT_TR[CONTEXT=Login]";
}
});
xhr.addEventListener("error", () => {
errorMsgElement.textContent = (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");
@@ -133,6 +62,4 @@ document.addEventListener("DOMContentLoaded", () => {
const loginForm = document.getElementById("loginform");
loginForm.method = "POST";
loginForm.addEventListener("submit", submitLoginForm);
setupI18n();
});