1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 14:46:36 +02:00

Use Lang::$translations instead of $translations

This commit is contained in:
Jakub Vrana
2025-03-29 22:43:44 +01:00
parent 30a8c4caca
commit 695ce8c4da
51 changed files with 69 additions and 70 deletions

View File

@@ -39,7 +39,7 @@ if ($_GET["script"] == "version") {
exit;
}
global $translations; // allows including Adminer inside a function
// Adminer doesn't use any global variables; they used to be declared here
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];

View File

@@ -62,8 +62,7 @@ function langs(): array {
*/
function lang(string $idf, $number = null): string {
// this is matched by compile.php
global $translations;
$translation = ($translations[$idf] ?: $idf);
$translation = (Lang::$translations[$idf] ?: $idf);
if (is_array($translation)) {
// this is matched by compile.php
$pos = ($number == 1 ? 0
@@ -99,7 +98,6 @@ function switch_lang(): void {
if (isset($_POST["lang"]) && verify_token()) { // $error not yet available
cookie("adminer_lang", $_POST["lang"]);
$_SESSION["lang"] = $_POST["lang"]; // cookies may be disabled
$_SESSION["translations"] = array(); // used in compiled version
redirect(remove_from_uri());
}
@@ -130,3 +128,7 @@ if (idx(langs(), $_COOKIE["adminer_lang"])) {
}
define('Adminer\LANG', $LANG);
class Lang {
/** @var array<literal-string, string|list<string>> */ static array $translations;
}

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'تسجيل الدخول',
'Logout successful.' => 'تم تسجيل الخروج بنجاح.',
'Invalid credentials.' => 'بيانات الدخول غير صالحة.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Система',
'Server' => 'Сървър',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'লগইন',
'Logout successful.' => 'সফলভাবে লগআউট হয়েছে।',
'Invalid credentials.' => 'ভুল পাসওয়ার্ড।',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistem',
'Server' => 'Server',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Inicia la sessió',
'Logout successful.' => 'Desconnexió correcta.',
'Invalid credentials.' => 'Credencials invàlides.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Systém',
'Server' => 'Server',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'System' => 'System',
'Server' => 'Server',
'Username' => 'Brugernavn',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Login',
'Logout successful.' => 'Abmeldung erfolgreich.',
'Thanks for using Adminer, consider <a href="https://www.adminer.org/en/donation/">donating</a>.' => 'Danke, dass Sie Adminer genutzt haben. <a href="https://www.adminer.org/de/donation/">Spenden willkommen!</a>.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Σύστημα',
'Server' => 'Διακομιστής',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Too many unsuccessful logins, try again in %d minute(s).' => array('Too many unsuccessful logins, try again in %d minute.', 'Too many unsuccessful logins, try again in %d minutes.'),
'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'),
'%d byte(s)' => array('%d byte', '%d bytes'),

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Login',
'Logout successful.' => 'Sesión finalizada con éxito.',
'Invalid credentials.' => 'Usuario y/o clave de acceso incorrecta.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Logi sisse',
'Logout successful.' => 'Väljalogimine õnnestus.',
'Invalid credentials.' => 'Ebakorrektsed andmed.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'سیستم',
'Server' => 'سرور',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Järjestelmä',
'Server' => 'Palvelin',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Authentification',
'Logout successful.' => 'Au revoir !',
'Invalid credentials.' => 'Authentification échouée.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Conectar',
'Logout successful.' => 'Pechouse a sesión con éxito.',
'Invalid credentials.' => 'Credenciais (usuario e/ou contrasinal) inválidos.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'התחברות',
'Logout successful.' => 'ההתחברות הצליחה',
'Invalid credentials.' => 'פרטי התחברות שגויים',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Belépés',
'Logout successful.' => 'Sikeres kilépés.',
'Invalid credentials.' => 'Érvénytelen adatok.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistem',
'Server' => 'Server',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Autenticazione',
'Logout successful.' => 'Uscita effettuata con successo.',
'Invalid credentials.' => 'Credenziali non valide.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'ログイン',
'Logout successful.' => 'ログアウトしました。',
'Invalid credentials.' => '不正なログインです。',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'შესვლა',
'Logout successful.' => 'გამოხვედით სისტემიდან.',
'Invalid credentials.' => 'არასწორი მომხმარებელი ან პაროლი.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'$1-$3-$5' => '$1-$3-$5',
'%.3f s' => '%.3f 초',
'%d byte(s)' => '%d 바이트',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistema',
'Server' => 'Serveris',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Ieiet',
'Logout successful.' => 'Jūs veiksmīgi izgājāt no sistēmas.',
'Invalid credentials.' => 'Nepareizs lietotāja vārds vai parole.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistem',
'Server' => 'Pelayan',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Aanmelden',
'Logout successful.' => 'Successvol afgemeld.',
'Invalid credentials.' => 'Ongeldige gebruikersgegevens.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'System' => 'System',
'Server' => 'Server',
'Username' => 'Brukernavn',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Rodzaj bazy',
'Server' => 'Serwer',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Entrar',
'Logout successful.' => 'Saída bem sucedida.',
'Invalid credentials.' => 'Identificação inválida.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Entrar',
'Logout successful.' => 'Sessão terminada com sucesso.',
'Invalid credentials.' => 'Identificação inválida.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Intră',
'Logout successful.' => 'Ați ieșit cu succes.',
'Invalid credentials.' => 'Numele de utilizator sau parola este greșită.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Войти',
'Logout successful.' => 'Вы успешно покинули систему.',
'Invalid credentials.' => 'Неправильное имя пользователя или пароль.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'Prihlásiť sa',
'Logout successful.' => 'Odhlásenie prebehlo v poriadku.',
'Invalid credentials.' => 'Neplatné prihlasovacie údaje.',
@@ -281,7 +281,7 @@ $translations = array(
'Warnings' => 'Varovania',
'%d / ' => '%d / ',
'Limit rows' => 'Limit riadkov',
'Adminer does not support accessing a database without a password, <a href="https://www.adminer.org/en/password/"%s>more information</a>.' => 'Adminer nepodporuje prístup k databáze bez hesla, <a href="https://www.adminer.org/cs/password/"%s>viac informácií</a>.',
'Adminer does not support accessing a database without a password, <a href="https://www.adminer.org/en/password/"%s>more information</a>.' => 'Adminer nepodporuje prístup k databáze bez hesla, <a href="https://www.adminer.org/en/password/"%s>viac informácií</a>.',
'Default value' => 'Predvolená hodnota',
'Full table scan' => 'Prechod celej tabuľky',
'Too many unsuccessful logins, try again in %d minute(s).' => array('Príliš veľa pokusov o prihlásenie, skúste to znova za %d minutu.', 'Príliš veľa pokusov o prihlásenie, skúste to znova za %d minuty.', 'Príliš veľa pokusov o prihlásenie, skúste to znova za %d minút.'),

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistem',
'Server' => 'Strežnik',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Систем',
'Server' => 'Сервер',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'System',
'Server' => 'Server',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'நுழை',
'Logout successful.' => 'வெற்றிக‌ர‌மாய் வெளியேறியாயிற்று.',
'Invalid credentials.' => 'ச‌ரியான‌ விப‌ர‌ங்க‌ள் இல்லை.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
'Login' => 'เข้าสู่ระบบ',
'Logout successful.' => 'ออกจากระบบเรียบร้อยแล้ว.',
'Invalid credentials.' => 'ข้อมูลไม่ถูกต้อง.',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Sistem',
'Server' => 'Sunucu',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Система Бази Даних',
'Server' => 'Сервер',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Tizim',
'Server' => 'Server',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Hệ thống',
'Server' => 'Máy chủ',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => 'Xx',
'Server' => 'Xx',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => '資料庫系統',
'Server' => '伺服器',

View File

@@ -1,7 +1,7 @@
<?php
namespace Adminer;
$translations = array(
Lang::$translations = array(
// label for database system selection (MySQL, SQLite, ...)
'System' => '系统',
'Server' => '服务器',

View File

@@ -18,9 +18,8 @@ function add_quo_slashes($s) {
}
function remove_lang($match) {
global $translations;
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
$s = ($translations[$idf] ?: $idf);
$s = (Adminer\Lang::$translations[$idf] ?: $idf);
if ($match[3] == ",") { // lang() has parameters
return $match[1] . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',");
}
@@ -167,9 +166,9 @@ function put_file_lang($match) {
}
$return = "";
foreach (Adminer\langs() as $lang => $val) {
include __DIR__ . "/adminer/lang/$lang.inc.php"; // assign $translations
include __DIR__ . "/adminer/lang/$lang.inc.php";
$translation_ids = array_flip($lang_ids); // default translation
foreach ($translations as $key => $val) {
foreach (Adminer\Lang::$translations as $key => $val) {
if ($val !== null) {
$translation_ids[$lang_ids[$key]] = implode("\t", (array) $val);
}
@@ -178,10 +177,14 @@ function put_file_lang($match) {
case "' . $lang . '": $compressed = "' . add_quo_slashes(lzw_compress(implode("\n", $translation_ids))) . '"; break;';
}
$translations_version = crc32($return);
return '$translations = $_SESSION["translations"];
if ($_SESSION["translations_version"] != ' . $translations_version . ') {
$translations = array();
$_SESSION["translations_version"] = ' . $translations_version . ';
return 'Lang::$translations = $_SESSION["translations"];
if ($_SESSION["translations_version"] != LANG . ' . $translations_version . ') {
Lang::$translations = array();
$_SESSION["translations_version"] = LANG . ' . $translations_version . ';
}
if (!Lang::$translations) {
Lang::$translations = get_translations(LANG);
$_SESSION["translations"] = Lang::$translations;
}
function get_translations($lang) {
@@ -193,11 +196,6 @@ function get_translations($lang) {
}
return $translations;
}
if (!$translations) {
$translations = get_translations(LANG);
$_SESSION["translations"] = $translations;
}
';
}

View File

@@ -5,8 +5,7 @@ include __DIR__ . "/adminer/include/errors.inc.php";
unset($_COOKIE["adminer_lang"]);
$_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
if (isset($_SESSION["lang"])) {
include __DIR__ . "/adminer/include/lang.inc.php";
if (isset($_SERVER["argv"][2]) || (!idx(Adminer\langs(), $_SESSION["lang"]) && $_SESSION["lang"] != "xx")) {
if (isset($_SERVER["argv"][2]) || !file_exists($filename)) {
echo "Usage: php lang.php [lang]\nPurpose: Update adminer/lang/*.inc.php from source code messages.\n";
exit(1);
}
@@ -20,9 +19,9 @@ foreach (
glob(__DIR__ . "/adminer/drivers/*.php"),
glob(__DIR__ . "/editor/*.php"),
glob(__DIR__ . "/editor/include/*.php")
) as $filename
) as $include
) {
$file = file_get_contents($filename);
$file = file_get_contents($include);
if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
$messages_all += array_combine($matches[1], $matches[2]);
}
@@ -70,7 +69,7 @@ foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.ph
}
}
}
$s = "<?php\nnamespace Adminer;\n\n\$translations = array(\n$s);\n\n// run `php ../../lang.php $lang` to update this file\n";
$s = "<?php\nnamespace Adminer;\n\nLang::\$translations = array(\n$s\t);\n\n// run `php ../../lang.php $lang` to update this file\n";
if ($s != $file) {
file_put_contents($filename, $s);
echo "$filename updated.\n";