From 4eb07d7006352176a8a27685b6909f1a2cb51a73 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 17 Jul 2007 14:04:29 +0000 Subject: [PATCH] Globalize $translations git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@216 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- _compile.php | 4 +- _lang.php | 6 +- lang.inc.php | 308 +++++++++++++++++++++++++-------------------------- 3 files changed, 158 insertions(+), 160 deletions(-) diff --git a/_compile.php b/_compile.php index ddbf518f..45f34728 100644 --- a/_compile.php +++ b/_compile.php @@ -37,7 +37,7 @@ error_reporting(E_ALL & ~E_NOTICE); if ($_SERVER["argc"] > 1) { $_COOKIE["lang"] = $_SERVER["argv"][1]; include "./lang.inc.php"; - if ($_SERVER["argc"] != 2 || !in_array($_SERVER["argv"][1], lang())) { + if ($_SERVER["argc"] != 2 || !isset($translations[$_COOKIE["lang"]])) { echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n"; exit(1); } @@ -51,7 +51,7 @@ $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*) if ($_COOKIE["lang"]) { $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file); $file = str_replace("\n", "", $file); - $file = str_replace("", $_COOKIE["lang"], $file); + $file = str_replace('', $_COOKIE["lang"], $file); } $file = str_replace("favicon.ico", '', $file); $file = str_replace("arrow.gif", '" . preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file); diff --git a/_lang.php b/_lang.php index be953b75..61921427 100644 --- a/_lang.php +++ b/_lang.php @@ -13,7 +13,7 @@ foreach (glob("*.php") as $filename) { } $file = file_get_contents("lang.inc.php"); -preg_match_all("~\n\t\t'(.*)' => array\\(\n(.*\n)\t\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE); +preg_match_all("~\n\t'(.*)' => array\\(\n(.*\n)\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE); foreach (array_reverse($translations[2], true) as $key => $translation) { $messages = $messages_all; preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER); @@ -28,9 +28,9 @@ foreach (array_reverse($translations[2], true) as $key => $translation) { } foreach($messages as $idf => $val) { if ($val == "," && strpos($idf, "%d")) { - $s .= "\t\t\t$idf => array(),\n"; + $s .= "\t\t$idf => array(),\n"; } elseif ($translations[1][$key][0] != 'en') { - $s .= "\t\t\t$idf => '',\n"; + $s .= "\t\t$idf => '',\n"; } } $file = substr_replace($file, $s, $translation[1], strlen($translation[0])); diff --git a/lang.inc.php b/lang.inc.php index 88fbe10b..2c4576e1 100644 --- a/lang.inc.php +++ b/lang.inc.php @@ -1,155 +1,153 @@ array( - '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'), - 'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'), - '%d process(es) has been killed.' => array('%d process has been killed.', '%d processes have been killed.'), - ), - 'cs' => array( - 'Login' => 'Přihlásit se', - 'phpMinAdmin' => 'phpMinAdmin', - 'Logout successful.' => 'Odhlášení proběhlo v pořádku.', - 'Invalid credentials.' => 'Neplatné přihlašovací údaje.', - 'Server' => 'Server', - 'Username' => 'Uživatel', - 'Password' => 'Heslo', - 'Select database' => 'Vybrat databázi', - 'Invalid database.' => 'Nesprávná databáze.', - 'Create new database' => 'Vytvořit novou databázi', - 'Table has been dropped.' => 'Tabulka byla odstraněna.', - 'Table has been altered.' => 'Tabulka byla změněna.', - 'Table has been created.' => 'Tabulka byla vytvořena.', - 'Alter table' => 'Pozměnit tabulku', - 'Create table' => 'Vytvořit tabulku', - 'Unable to operate table' => 'Nepodařilo se zpracovat tabulku', - 'Table name' => 'Název tabulky', - 'engine' => 'typ tabulky', - 'collation' => 'porovnávání', - 'Column name' => 'Název sloupce', - 'Type' => 'Typ', - 'Length' => 'Délka', - 'NULL' => 'NULL', - 'Auto Increment' => 'Auto Increment', - 'Options' => 'Volby', - 'Save' => 'Uložit', - 'Drop' => 'Odstranit', - 'Database has been dropped.' => 'Databáze byla odstraněna.', - 'Database has been created.' => 'Databáze byla vytvořena.', - 'Database has been renamed.' => 'Databáze byla přejmenována.', - 'Database has been altered.' => 'Databáze byla změněna.', - 'Alter database' => 'Pozměnit databázi', - 'Create database' => 'Vytvořit databázi', - 'Unable to operate database' => 'Nepodařilo se zpracovat databázi', - 'SQL command' => 'SQL příkaz', - 'Dump' => 'Export', - 'Logout' => 'Odhlásit', - 'database' => 'databáze', - 'Use' => 'Vybrat', - 'No tables.' => 'Žádné tabulky.', - 'select' => 'vypsat', - 'Create new table' => 'Vytvořit novou tabulku', - 'Item has been deleted.' => 'Položka byla smazána.', - 'Item has been updated.' => 'Položka byla aktualizována.', - 'Item has been inserted.' => 'Položka byla vložena.', - 'Edit' => 'Upravit', - 'Insert' => 'Vložit', - 'Error during saving' => 'Chyba při ukládání', - 'Save and insert' => 'Uložit a vložit', - 'Delete' => 'Smazat', - 'Database' => 'Databáze', - 'Routines' => 'Procedury', - 'Indexes has been altered.' => 'Indexy byly změněny.', - 'Indexes' => 'Indexy', - 'Unable to operate indexes' => 'Nepodařilo se zpracovat indexy', - 'Alter indexes' => 'Pozměnit indexy', - 'Add next' => 'Přidat další', - 'Language' => 'Jazyk', - 'Select' => 'Vypsat', - 'New item' => 'Nová položka', - 'Search' => 'Vyhledat', - 'Sort' => 'Setřídit', - 'DESC' => 'sestupně', - 'Limit' => 'Limit', - 'No rows.' => 'Žádné řádky.', - 'Action' => 'Akce', - 'edit' => 'upravit', - 'Page' => 'Stránka', - 'Query executed OK, %d row(s) affected.' => array('Příkaz proběhl v pořádku, byl změněn %d záznam.', 'Příkaz proběhl v pořádku, byly změněny %d záznamy.', 'Příkaz proběhl v pořádku, bylo změněno %d záznamů.'), - 'Error in query' => 'Chyba v dotazu', - 'Execute' => 'Provést', - 'Table' => 'Tabulka', - 'Foreign keys' => 'Cizí klíče', - 'Triggers' => 'Spouště', - 'View' => 'Pohled', - 'Unable to select the table' => 'Nepodařilo se vypsat tabulku', - 'Unable to show the table definition' => 'Nepodařilo se získat strukturu tabulky', - 'Invalid CSRF token. Send the form again.' => 'Neplatný token CSRF. Odešlete formulář znovu.', - 'Comment' => 'Komentář', - 'Default values has been set.' => 'Výchozí hodnoty byly nastaveny.', - 'Default values' => 'Výchozí hodnoty', - 'BOOL' => 'BOOL', - 'Show column comments' => 'Zobrazit komentáře sloupců', - '%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'), - 'No commands to execute.' => 'Žádné příkazy k vykonání.', - 'Unable to upload a file.' => 'Nepodařilo se nahrát soubor.', - 'File upload' => 'Nahrání souboru', - 'File uploads are disabled.' => 'Nahrávání souborů není povoleno.', - 'Routine has been called, %d row(s) affected.' => array('Procedura byla zavolána, byl změněn %d záznam.', 'Procedura byla zavolána, byly změněny %d záznamy.', 'Procedura byla zavolána, bylo změněno %d záznamů.'), - 'Call' => 'Zavolat', - 'Error during calling' => 'Chyba při volání', - 'No MySQL extension' => 'Žádná MySQL extenze', - 'None of supported PHP extensions (%s) are available.' => 'Není dostupná žádná z podporovaných PHP extenzí (%s).', - 'Sessions must be enabled.' => 'Session proměnné musí být povolené.', - 'Session expired, please login again.' => 'Session vypršela, přihlašte se prosím znovu.', - 'Text length' => 'Délka textů', - 'Syntax highlighting' => 'Zvýrazňování syntaxe', - 'Foreign key has been dropped.' => 'Cizí klíč byl odstraněn.', - 'Foreign key has been altered.' => 'Cizí klíč byl změněn.', - 'Foreign key has been created.' => 'Cizí klíč byl vytvořen.', - 'Foreign key' => 'Cizí klíč', - 'Unable to operate foreign keys' => 'Nepodařilo se zpracovat cizí klíče', - 'Target table' => 'Cílová tabulka', - 'Change' => 'Změnit', - 'Source' => 'Zdroj', - 'Target' => 'Cíl', - 'Add column' => 'Přidat sloupec', - 'Alter' => 'Změnit', - 'Add foreign key' => 'Přidat cizí klíč', - 'ON DELETE' => 'ON DELETE', - 'ON UPDATE' => 'ON UPDATE', - 'Index Type' => 'Typ indexu', - 'Column (length)' => 'Sloupec (délka)', - 'View has been dropped.' => 'Pohled byl odstraněn.', - 'View has been altered.' => 'Pohled byl změněn.', - 'View has been created.' => 'Pohled byl vytvořen.', - 'Alter view' => 'Pozměnit pohled', - 'Create view' => 'Vytvořit pohled', - 'Unable to operate view' => 'Nepodařilo se zpracovat pohled', - 'Name' => 'Název', - 'Process list' => 'Seznam procesů', - '%d process(es) has been killed.' => array('Byl ukončen %d proces.', 'Byly ukončeny %d procesy.', 'Bylo ukončeno %d procesů.'), - 'Unable to kill process' => 'Nepodařilo se ukončit proces.', - 'Kill' => 'Ukončit', - 'IN-OUT' => 'IN-OUT', - 'Parameter name' => 'Název parametru', - 'Database schema' => 'Schéma databáze', - 'Create procedure' => 'Vytvořit proceduru', - 'Create function' => 'Vytvořit funkci', - 'Routine has been dropped.' => 'Procedura byla odstraněna.', - 'Routine has been altered.' => 'Procedura byla změněna.', - 'Routine has been created.' => 'Procedura byla vytvořena.', - 'Alter function' => 'Změnit funkci', - 'Alter procedure' => 'Změnit proceduru', - 'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru', - 'Return type' => 'Návratový typ', - ), - ); - if (!isset($idf)) { - return array_keys($translations); - } +static $translations = array( + 'en' => array( + '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'), + 'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'), + '%d process(es) has been killed.' => array('%d process has been killed.', '%d processes have been killed.'), + ), + 'cs' => array( + 'Login' => 'Přihlásit se', + 'phpMinAdmin' => 'phpMinAdmin', + 'Logout successful.' => 'Odhlášení proběhlo v pořádku.', + 'Invalid credentials.' => 'Neplatné přihlašovací údaje.', + 'Server' => 'Server', + 'Username' => 'Uživatel', + 'Password' => 'Heslo', + 'Select database' => 'Vybrat databázi', + 'Invalid database.' => 'Nesprávná databáze.', + 'Create new database' => 'Vytvořit novou databázi', + 'Table has been dropped.' => 'Tabulka byla odstraněna.', + 'Table has been altered.' => 'Tabulka byla změněna.', + 'Table has been created.' => 'Tabulka byla vytvořena.', + 'Alter table' => 'Pozměnit tabulku', + 'Create table' => 'Vytvořit tabulku', + 'Unable to operate table' => 'Nepodařilo se zpracovat tabulku', + 'Table name' => 'Název tabulky', + 'engine' => 'typ tabulky', + 'collation' => 'porovnávání', + 'Column name' => 'Název sloupce', + 'Type' => 'Typ', + 'Length' => 'Délka', + 'NULL' => 'NULL', + 'Auto Increment' => 'Auto Increment', + 'Options' => 'Volby', + 'Save' => 'Uložit', + 'Drop' => 'Odstranit', + 'Database has been dropped.' => 'Databáze byla odstraněna.', + 'Database has been created.' => 'Databáze byla vytvořena.', + 'Database has been renamed.' => 'Databáze byla přejmenována.', + 'Database has been altered.' => 'Databáze byla změněna.', + 'Alter database' => 'Pozměnit databázi', + 'Create database' => 'Vytvořit databázi', + 'Unable to operate database' => 'Nepodařilo se zpracovat databázi', + 'SQL command' => 'SQL příkaz', + 'Dump' => 'Export', + 'Logout' => 'Odhlásit', + 'database' => 'databáze', + 'Use' => 'Vybrat', + 'No tables.' => 'Žádné tabulky.', + 'select' => 'vypsat', + 'Create new table' => 'Vytvořit novou tabulku', + 'Item has been deleted.' => 'Položka byla smazána.', + 'Item has been updated.' => 'Položka byla aktualizována.', + 'Item has been inserted.' => 'Položka byla vložena.', + 'Edit' => 'Upravit', + 'Insert' => 'Vložit', + 'Error during saving' => 'Chyba při ukládání', + 'Save and insert' => 'Uložit a vložit', + 'Delete' => 'Smazat', + 'Database' => 'Databáze', + 'Routines' => 'Procedury', + 'Indexes has been altered.' => 'Indexy byly změněny.', + 'Indexes' => 'Indexy', + 'Unable to operate indexes' => 'Nepodařilo se zpracovat indexy', + 'Alter indexes' => 'Pozměnit indexy', + 'Add next' => 'Přidat další', + 'Language' => 'Jazyk', + 'Select' => 'Vypsat', + 'New item' => 'Nová položka', + 'Search' => 'Vyhledat', + 'Sort' => 'Setřídit', + 'DESC' => 'sestupně', + 'Limit' => 'Limit', + 'No rows.' => 'Žádné řádky.', + 'Action' => 'Akce', + 'edit' => 'upravit', + 'Page' => 'Stránka', + 'Query executed OK, %d row(s) affected.' => array('Příkaz proběhl v pořádku, byl změněn %d záznam.', 'Příkaz proběhl v pořádku, byly změněny %d záznamy.', 'Příkaz proběhl v pořádku, bylo změněno %d záznamů.'), + 'Error in query' => 'Chyba v dotazu', + 'Execute' => 'Provést', + 'Table' => 'Tabulka', + 'Foreign keys' => 'Cizí klíče', + 'Triggers' => 'Spouště', + 'View' => 'Pohled', + 'Unable to select the table' => 'Nepodařilo se vypsat tabulku', + 'Unable to show the table definition' => 'Nepodařilo se získat strukturu tabulky', + 'Invalid CSRF token. Send the form again.' => 'Neplatný token CSRF. Odešlete formulář znovu.', + 'Comment' => 'Komentář', + 'Default values has been set.' => 'Výchozí hodnoty byly nastaveny.', + 'Default values' => 'Výchozí hodnoty', + 'BOOL' => 'BOOL', + 'Show column comments' => 'Zobrazit komentáře sloupců', + '%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'), + 'No commands to execute.' => 'Žádné příkazy k vykonání.', + 'Unable to upload a file.' => 'Nepodařilo se nahrát soubor.', + 'File upload' => 'Nahrání souboru', + 'File uploads are disabled.' => 'Nahrávání souborů není povoleno.', + 'Routine has been called, %d row(s) affected.' => array('Procedura byla zavolána, byl změněn %d záznam.', 'Procedura byla zavolána, byly změněny %d záznamy.', 'Procedura byla zavolána, bylo změněno %d záznamů.'), + 'Call' => 'Zavolat', + 'Error during calling' => 'Chyba při volání', + 'No MySQL extension' => 'Žádná MySQL extenze', + 'None of supported PHP extensions (%s) are available.' => 'Není dostupná žádná z podporovaných PHP extenzí (%s).', + 'Sessions must be enabled.' => 'Session proměnné musí být povolené.', + 'Session expired, please login again.' => 'Session vypršela, přihlašte se prosím znovu.', + 'Text length' => 'Délka textů', + 'Syntax highlighting' => 'Zvýrazňování syntaxe', + 'Foreign key has been dropped.' => 'Cizí klíč byl odstraněn.', + 'Foreign key has been altered.' => 'Cizí klíč byl změněn.', + 'Foreign key has been created.' => 'Cizí klíč byl vytvořen.', + 'Foreign key' => 'Cizí klíč', + 'Unable to operate foreign keys' => 'Nepodařilo se zpracovat cizí klíče', + 'Target table' => 'Cílová tabulka', + 'Change' => 'Změnit', + 'Source' => 'Zdroj', + 'Target' => 'Cíl', + 'Add column' => 'Přidat sloupec', + 'Alter' => 'Změnit', + 'Add foreign key' => 'Přidat cizí klíč', + 'ON DELETE' => 'ON DELETE', + 'ON UPDATE' => 'ON UPDATE', + 'Index Type' => 'Typ indexu', + 'Column (length)' => 'Sloupec (délka)', + 'View has been dropped.' => 'Pohled byl odstraněn.', + 'View has been altered.' => 'Pohled byl změněn.', + 'View has been created.' => 'Pohled byl vytvořen.', + 'Alter view' => 'Pozměnit pohled', + 'Create view' => 'Vytvořit pohled', + 'Unable to operate view' => 'Nepodařilo se zpracovat pohled', + 'Name' => 'Název', + 'Process list' => 'Seznam procesů', + '%d process(es) has been killed.' => array('Byl ukončen %d proces.', 'Byly ukončeny %d procesy.', 'Bylo ukončeno %d procesů.'), + 'Unable to kill process' => 'Nepodařilo se ukončit proces.', + 'Kill' => 'Ukončit', + 'IN-OUT' => 'IN-OUT', + 'Parameter name' => 'Název parametru', + 'Database schema' => 'Schéma databáze', + 'Create procedure' => 'Vytvořit proceduru', + 'Create function' => 'Vytvořit funkci', + 'Routine has been dropped.' => 'Procedura byla odstraněna.', + 'Routine has been altered.' => 'Procedura byla změněna.', + 'Routine has been created.' => 'Procedura byla vytvořena.', + 'Alter function' => 'Změnit funkci', + 'Alter procedure' => 'Změnit proceduru', + 'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru', + 'Return type' => '', + ), +); + +function lang($idf, $number = null) { + global $LANG, $translations; $translation = $translations[$LANG][$idf]; if ($number === false) { // used in _compile.php return ($translation ? $translation : $idf); @@ -169,9 +167,10 @@ function lang($idf = null, $number = null) { } function switch_lang() { + global $translations; echo "

" . lang('Language') . ":"; $base = preg_replace('~(\\?)lang=[^&]*&|[&?]lang=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]); - foreach (lang() as $lang) { + foreach ($translations as $lang => $val) { echo ' $lang"; } echo "

\n"; @@ -185,11 +184,10 @@ if (isset($_GET["lang"])) { if (strlen($_COOKIE["lang"])) { $LANG = $_COOKIE["lang"]; } else { - $langs = lang(); $LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); - if (!in_array($LANG, $langs)) { //! try next languages + if (!isset($translations[$LANG])) { //! try next languages $LANG = preg_replace('~-.*~', '', $LANG); - if (!in_array($LANG, $langs)) { + if (!isset($translations[$LANG])) { $LANG = "en"; } }