Globalize $translations

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@216 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-17 14:04:29 +00:00
parent 57391acbca
commit 4eb07d7006
3 changed files with 158 additions and 160 deletions

View file

@ -37,7 +37,7 @@ error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) { if ($_SERVER["argc"] > 1) {
$_COOKIE["lang"] = $_SERVER["argv"][1]; $_COOKIE["lang"] = $_SERVER["argv"][1];
include "./lang.inc.php"; 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"; echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
exit(1); exit(1);
} }
@ -51,7 +51,7 @@ $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)
if ($_COOKIE["lang"]) { if ($_COOKIE["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file); $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("<?php switch_lang(); ?>\n", "", $file); $file = str_replace("<?php switch_lang(); ?>\n", "", $file);
$file = str_replace("<?php echo get_lang(); ?>", $_COOKIE["lang"], $file); $file = str_replace('<?php echo $LANG; ?>', $_COOKIE["lang"], $file);
} }
$file = str_replace("favicon.ico", '<?php echo preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?favicon="; ?>', $file); $file = str_replace("favicon.ico", '<?php echo preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?favicon="; ?>', $file);
$file = str_replace("arrow.gif", '" . preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file); $file = str_replace("arrow.gif", '" . preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file);

View file

@ -13,7 +13,7 @@ foreach (glob("*.php") as $filename) {
} }
$file = file_get_contents("lang.inc.php"); $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) { foreach (array_reverse($translations[2], true) as $key => $translation) {
$messages = $messages_all; $messages = $messages_all;
preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER); 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) { foreach($messages as $idf => $val) {
if ($val == "," && strpos($idf, "%d")) { if ($val == "," && strpos($idf, "%d")) {
$s .= "\t\t\t$idf => array(),\n"; $s .= "\t\t$idf => array(),\n";
} elseif ($translations[1][$key][0] != 'en') { } 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])); $file = substr_replace($file, $s, $translation[1], strlen($translation[0]));

View file

@ -1,155 +1,153 @@
<?php <?php
function lang($idf = null, $number = null) { static $translations = array(
global $LANG; 'en' => array(
static $translations = array( 'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'),
'en' => array( '%d byte(s)' => array('%d byte', '%d bytes'),
'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'), 'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'),
'%d byte(s)' => array('%d byte', '%d bytes'), '%d process(es) has been killed.' => array('%d process has been killed.', '%d processes have been killed.'),
'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',
'cs' => array( 'phpMinAdmin' => 'phpMinAdmin',
'Login' => 'Přihlásit se', 'Logout successful.' => 'Odhlášení proběhlo v pořádku.',
'phpMinAdmin' => 'phpMinAdmin', 'Invalid credentials.' => 'Neplatné přihlašovací údaje.',
'Logout successful.' => 'Odhlášení proběhlo v pořádku.', 'Server' => 'Server',
'Invalid credentials.' => 'Neplatné přihlašovací údaje.', 'Username' => 'Uživatel',
'Server' => 'Server', 'Password' => 'Heslo',
'Username' => 'Uživatel', 'Select database' => 'Vybrat databázi',
'Password' => 'Heslo', 'Invalid database.' => 'Nesprávná databáze.',
'Select database' => 'Vybrat databázi', 'Create new database' => 'Vytvořit novou databázi',
'Invalid database.' => 'Nesprávná databáze.', 'Table has been dropped.' => 'Tabulka byla odstraněna.',
'Create new database' => 'Vytvořit novou databázi', 'Table has been altered.' => 'Tabulka byla změněna.',
'Table has been dropped.' => 'Tabulka byla odstraněna.', 'Table has been created.' => 'Tabulka byla vytvořena.',
'Table has been altered.' => 'Tabulka byla změněna.', 'Alter table' => 'Pozměnit tabulku',
'Table has been created.' => 'Tabulka byla vytvořena.', 'Create table' => 'Vytvořit tabulku',
'Alter table' => 'Pozměnit tabulku', 'Unable to operate table' => 'Nepodařilo se zpracovat tabulku',
'Create table' => 'Vytvořit tabulku', 'Table name' => 'Název tabulky',
'Unable to operate table' => 'Nepodařilo se zpracovat tabulku', 'engine' => 'typ tabulky',
'Table name' => 'Název tabulky', 'collation' => 'porovnávání',
'engine' => 'typ tabulky', 'Column name' => 'Název sloupce',
'collation' => 'porovnávání', 'Type' => 'Typ',
'Column name' => 'Název sloupce', 'Length' => 'Délka',
'Type' => 'Typ', 'NULL' => 'NULL',
'Length' => 'Délka', 'Auto Increment' => 'Auto Increment',
'NULL' => 'NULL', 'Options' => 'Volby',
'Auto Increment' => 'Auto Increment', 'Save' => 'Uložit',
'Options' => 'Volby', 'Drop' => 'Odstranit',
'Save' => 'Uložit', 'Database has been dropped.' => 'Databáze byla odstraněna.',
'Drop' => 'Odstranit', 'Database has been created.' => 'Databáze byla vytvořena.',
'Database has been dropped.' => 'Databáze byla odstraněna.', 'Database has been renamed.' => 'Databáze byla přejmenována.',
'Database has been created.' => 'Databáze byla vytvořena.', 'Database has been altered.' => 'Databáze byla změněna.',
'Database has been renamed.' => 'Databáze byla přejmenována.', 'Alter database' => 'Pozměnit databázi',
'Database has been altered.' => 'Databáze byla změněna.', 'Create database' => 'Vytvořit databázi',
'Alter database' => 'Pozměnit databázi', 'Unable to operate database' => 'Nepodařilo se zpracovat databázi',
'Create database' => 'Vytvořit databázi', 'SQL command' => 'SQL příkaz',
'Unable to operate database' => 'Nepodařilo se zpracovat databázi', 'Dump' => 'Export',
'SQL command' => 'SQL příkaz', 'Logout' => 'Odhlásit',
'Dump' => 'Export', 'database' => 'databáze',
'Logout' => 'Odhlásit', 'Use' => 'Vybrat',
'database' => 'databáze', 'No tables.' => 'Žádné tabulky.',
'Use' => 'Vybrat', 'select' => 'vypsat',
'No tables.' => 'Žádné tabulky.', 'Create new table' => 'Vytvořit novou tabulku',
'select' => 'vypsat', 'Item has been deleted.' => 'Položka byla smazána.',
'Create new table' => 'Vytvořit novou tabulku', 'Item has been updated.' => 'Položka byla aktualizována.',
'Item has been deleted.' => 'Položka byla smazána.', 'Item has been inserted.' => 'Položka byla vložena.',
'Item has been updated.' => 'Položka byla aktualizována.', 'Edit' => 'Upravit',
'Item has been inserted.' => 'Položka byla vložena.', 'Insert' => 'Vložit',
'Edit' => 'Upravit', 'Error during saving' => 'Chyba při ukládání',
'Insert' => 'Vložit', 'Save and insert' => 'Uložit a vložit',
'Error during saving' => 'Chyba při ukládání', 'Delete' => 'Smazat',
'Save and insert' => 'Uložit a vložit', 'Database' => 'Databáze',
'Delete' => 'Smazat', 'Routines' => 'Procedury',
'Database' => 'Databáze', 'Indexes has been altered.' => 'Indexy byly změněny.',
'Routines' => 'Procedury', 'Indexes' => 'Indexy',
'Indexes has been altered.' => 'Indexy byly změněny.', 'Unable to operate indexes' => 'Nepodařilo se zpracovat indexy',
'Indexes' => 'Indexy', 'Alter indexes' => 'Pozměnit indexy',
'Unable to operate indexes' => 'Nepodařilo se zpracovat indexy', 'Add next' => 'Přidat další',
'Alter indexes' => 'Pozměnit indexy', 'Language' => 'Jazyk',
'Add next' => 'Přidat další', 'Select' => 'Vypsat',
'Language' => 'Jazyk', 'New item' => 'Nová položka',
'Select' => 'Vypsat', 'Search' => 'Vyhledat',
'New item' => 'Nová položka', 'Sort' => 'Setřídit',
'Search' => 'Vyhledat', 'DESC' => 'sestupně',
'Sort' => 'Setřídit', 'Limit' => 'Limit',
'DESC' => 'sestupně', 'No rows.' => 'Žádné řádky.',
'Limit' => 'Limit', 'Action' => 'Akce',
'No rows.' => 'Žádné řádky.', 'edit' => 'upravit',
'Action' => 'Akce', 'Page' => 'Stránka',
'edit' => 'upravit', '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ů.'),
'Page' => 'Stránka', 'Error in query' => 'Chyba v dotazu',
'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ů.'), 'Execute' => 'Provést',
'Error in query' => 'Chyba v dotazu', 'Table' => 'Tabulka',
'Execute' => 'Provést', 'Foreign keys' => 'Cizí klíče',
'Table' => 'Tabulka', 'Triggers' => 'Spouště',
'Foreign keys' => 'Cizí klíče', 'View' => 'Pohled',
'Triggers' => 'Spouště', 'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
'View' => 'Pohled', 'Unable to show the table definition' => 'Nepodařilo se získat strukturu tabulky',
'Unable to select the table' => 'Nepodařilo se vypsat tabulku', 'Invalid CSRF token. Send the form again.' => 'Neplatný token CSRF. Odešlete formulář znovu.',
'Unable to show the table definition' => 'Nepodařilo se získat strukturu tabulky', 'Comment' => 'Komentář',
'Invalid CSRF token. Send the form again.' => 'Neplatný token CSRF. Odešlete formulář znovu.', 'Default values has been set.' => 'Výchozí hodnoty byly nastaveny.',
'Comment' => 'Komentář', 'Default values' => 'Výchozí hodnoty',
'Default values has been set.' => 'Výchozí hodnoty byly nastaveny.', 'BOOL' => 'BOOL',
'Default values' => 'Výchozí hodnoty', 'Show column comments' => 'Zobrazit komentáře sloupců',
'BOOL' => 'BOOL', '%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'),
'Show column comments' => 'Zobrazit komentáře sloupců', 'No commands to execute.' => 'Žádné příkazy k vykonání.',
'%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'), 'Unable to upload a file.' => 'Nepodařilo se nahrát soubor.',
'No commands to execute.' => 'Žádné příkazy k vykonání.', 'File upload' => 'Nahrání souboru',
'Unable to upload a file.' => 'Nepodařilo se nahrát soubor.', 'File uploads are disabled.' => 'Nahrávání souborů není povoleno.',
'File upload' => 'Nahrání souboru', '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ů.'),
'File uploads are disabled.' => 'Nahrávání souborů není povoleno.', 'Call' => 'Zavolat',
'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ů.'), 'Error during calling' => 'Chyba při volání',
'Call' => 'Zavolat', 'No MySQL extension' => 'Žádná MySQL extenze',
'Error during calling' => 'Chyba při volání', 'None of supported PHP extensions (%s) are available.' => 'Není dostupná žádná z podporovaných PHP extenzí (%s).',
'No MySQL extension' => 'Žádná MySQL extenze', 'Sessions must be enabled.' => 'Session proměnné musí být povolené.',
'None of supported PHP extensions (%s) are available.' => 'Není dostupná žádná z podporovaných PHP extenzí (%s).', 'Session expired, please login again.' => 'Session vypršela, přihlašte se prosím znovu.',
'Sessions must be enabled.' => 'Session proměnné musí být povolené.', 'Text length' => 'Délka textů',
'Session expired, please login again.' => 'Session vypršela, přihlašte se prosím znovu.', 'Syntax highlighting' => 'Zvýrazňování syntaxe',
'Text length' => 'Délka textů', 'Foreign key has been dropped.' => 'Cizí klíč byl odstraněn.',
'Syntax highlighting' => 'Zvýrazňování syntaxe', 'Foreign key has been altered.' => 'Cizí klíč byl změněn.',
'Foreign key has been dropped.' => 'Cizí klíč byl odstraněn.', 'Foreign key has been created.' => 'Cizí klíč byl vytvořen.',
'Foreign key has been altered.' => 'Cizí klíč byl změněn.', 'Foreign key' => 'Cizí klíč',
'Foreign key has been created.' => 'Cizí klíč byl vytvořen.', 'Unable to operate foreign keys' => 'Nepodařilo se zpracovat cizí klíče',
'Foreign key' => 'Cizí klíč', 'Target table' => 'Cílová tabulka',
'Unable to operate foreign keys' => 'Nepodařilo se zpracovat cizí klíče', 'Change' => 'Změnit',
'Target table' => 'Cílová tabulka', 'Source' => 'Zdroj',
'Change' => 'Změnit', 'Target' => 'Cíl',
'Source' => 'Zdroj', 'Add column' => 'Přidat sloupec',
'Target' => 'Cíl', 'Alter' => 'Změnit',
'Add column' => 'Přidat sloupec', 'Add foreign key' => 'Přidat cizí klíč',
'Alter' => 'Změnit', 'ON DELETE' => 'ON DELETE',
'Add foreign key' => 'Přidat cizí klíč', 'ON UPDATE' => 'ON UPDATE',
'ON DELETE' => 'ON DELETE', 'Index Type' => 'Typ indexu',
'ON UPDATE' => 'ON UPDATE', 'Column (length)' => 'Sloupec (délka)',
'Index Type' => 'Typ indexu', 'View has been dropped.' => 'Pohled byl odstraněn.',
'Column (length)' => 'Sloupec (délka)', 'View has been altered.' => 'Pohled byl změněn.',
'View has been dropped.' => 'Pohled byl odstraněn.', 'View has been created.' => 'Pohled byl vytvořen.',
'View has been altered.' => 'Pohled byl změněn.', 'Alter view' => 'Pozměnit pohled',
'View has been created.' => 'Pohled byl vytvořen.', 'Create view' => 'Vytvořit pohled',
'Alter view' => 'Pozměnit pohled', 'Unable to operate view' => 'Nepodařilo se zpracovat pohled',
'Create view' => 'Vytvořit pohled', 'Name' => 'Název',
'Unable to operate view' => 'Nepodařilo se zpracovat pohled', 'Process list' => 'Seznam procesů',
'Name' => 'Název', '%d process(es) has been killed.' => array('Byl ukončen %d proces.', 'Byly ukončeny %d procesy.', 'Bylo ukončeno %d procesů.'),
'Process list' => 'Seznam procesů', 'Unable to kill process' => 'Nepodařilo se ukončit proces.',
'%d process(es) has been killed.' => array('Byl ukončen %d proces.', 'Byly ukončeny %d procesy.', 'Bylo ukončeno %d procesů.'), 'Kill' => 'Ukončit',
'Unable to kill process' => 'Nepodařilo se ukončit proces.', 'IN-OUT' => 'IN-OUT',
'Kill' => 'Ukončit', 'Parameter name' => 'Název parametru',
'IN-OUT' => 'IN-OUT', 'Database schema' => 'Schéma databáze',
'Parameter name' => 'Název parametru', 'Create procedure' => 'Vytvořit proceduru',
'Database schema' => 'Schéma databáze', 'Create function' => 'Vytvořit funkci',
'Create procedure' => 'Vytvořit proceduru', 'Routine has been dropped.' => 'Procedura byla odstraněna.',
'Create function' => 'Vytvořit funkci', 'Routine has been altered.' => 'Procedura byla změněna.',
'Routine has been dropped.' => 'Procedura byla odstraněna.', 'Routine has been created.' => 'Procedura byla vytvořena.',
'Routine has been altered.' => 'Procedura byla změněna.', 'Alter function' => 'Změnit funkci',
'Routine has been created.' => 'Procedura byla vytvořena.', 'Alter procedure' => 'Změnit proceduru',
'Alter function' => 'Změnit funkci', 'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru',
'Alter procedure' => 'Změnit proceduru', 'Return type' => '',
'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru', ),
'Return type' => 'Návratový typ', );
),
); function lang($idf, $number = null) {
if (!isset($idf)) { global $LANG, $translations;
return array_keys($translations);
}
$translation = $translations[$LANG][$idf]; $translation = $translations[$LANG][$idf];
if ($number === false) { // used in _compile.php if ($number === false) { // used in _compile.php
return ($translation ? $translation : $idf); return ($translation ? $translation : $idf);
@ -169,9 +167,10 @@ function lang($idf = null, $number = null) {
} }
function switch_lang() { function switch_lang() {
global $translations;
echo "<p>" . lang('Language') . ":"; echo "<p>" . lang('Language') . ":";
$base = preg_replace('~(\\?)lang=[^&]*&|[&?]lang=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]); $base = preg_replace('~(\\?)lang=[^&]*&|[&?]lang=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]);
foreach (lang() as $lang) { foreach ($translations as $lang => $val) {
echo ' <a href="' . htmlspecialchars($base . (strpos($base, "?") !== false ? "&" : "?")) . "lang=$lang\">$lang</a>"; echo ' <a href="' . htmlspecialchars($base . (strpos($base, "?") !== false ? "&" : "?")) . "lang=$lang\">$lang</a>";
} }
echo "</p>\n"; echo "</p>\n";
@ -185,11 +184,10 @@ if (isset($_GET["lang"])) {
if (strlen($_COOKIE["lang"])) { if (strlen($_COOKIE["lang"])) {
$LANG = $_COOKIE["lang"]; $LANG = $_COOKIE["lang"];
} else { } else {
$langs = lang();
$LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); $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); $LANG = preg_replace('~-.*~', '', $LANG);
if (!in_array($LANG, $langs)) { if (!isset($translations[$LANG])) {
$LANG = "en"; $LANG = "en";
} }
} }