Flatten $translations

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@290 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-08-04 19:36:01 +00:00
parent 81dbdda552
commit bba76d8df6
5 changed files with 18 additions and 19 deletions

View file

@ -4,9 +4,9 @@ function add_apo_slashes($s) {
} }
function remove_lang($match) { function remove_lang($match) {
global $LANG, $translations; global $translations;
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\")); $idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
$s = ($translations[$LANG][$idf] ? $translations[$LANG][$idf] : $idf); $s = ($translations[$idf] ? $translations[$idf] : $idf);
if ($match[3] == ",") { if ($match[3] == ",") {
return "$match[1]" . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',"); return "$match[1]" . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',");
} }
@ -15,14 +15,14 @@ function remove_lang($match) {
function put_file($match) { function put_file($match) {
if ($match[4] == './lang/$LANG.inc.php') { if ($match[4] == './lang/$LANG.inc.php') {
$return = ""; if ($_COOKIE["lang"]) {
if (!$_COOKIE["lang"]) { return "";
foreach (glob("./lang/*.inc.php") as $filename) {
$match[4] = $filename;
$return .= put_file($match);
}
} }
return $return; $return = "switch (\$LANG) {\n";
foreach (glob("./lang/*.inc.php") as $filename) {
$return .= "case '" . basename($filename, '.inc.php') . "': " . substr(file_get_contents($filename), 6) . "break;\n";
}
return "$return}\n";
} }
$return = file_get_contents($match[4]); $return = file_get_contents($match[4]);
if ($match[4] == "./lang.inc.php" && $_COOKIE["lang"] && (preg_match("~case '$_COOKIE[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2))) { if ($match[4] == "./lang.inc.php" && $_COOKIE["lang"] && (preg_match("~case '$_COOKIE[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2))) {
@ -45,17 +45,15 @@ 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 || !isset($translations[$_COOKIE["lang"]])) { if ($_SERVER["argc"] != 2 || !isset($langs[$_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);
} }
include "./lang/$_COOKIE[lang].inc.php"; include "./lang/$_COOKIE[lang].inc.php";
} }
$filename = "phpMinAdmin.php";
$filename = "phpMinAdmin" . ($_COOKIE["lang"] ? "-$_COOKIE[lang]" : "") . ".php";
$file = file_get_contents("index.php"); $file = file_get_contents("index.php");
if ($_COOKIE["lang"]) {
$filename = "phpMinAdmin-$_COOKIE[lang].php";
}
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file); $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
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);

View file

@ -1,8 +1,9 @@
<?php <?php
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 || !isset($translations[$_COOKIE["lang"]])) { if ($_SERVER["argc"] != 2 || !isset($langs[$_COOKIE["lang"]])) {
echo "Usage: php _lang.php [lang]\nPurpose: Update lang.inc.php from source code messages.\n"; echo "Usage: php _lang.php [lang]\nPurpose: Update lang.inc.php from source code messages.\n";
exit(1); exit(1);
} }
@ -19,7 +20,7 @@ foreach (glob("*.php") as $filename) {
foreach (($_COOKIE["lang"] ? array("lang/$_COOKIE[lang].inc.php") : glob("lang/*.inc.php")) as $filename) { foreach (($_COOKIE["lang"] ? array("lang/$_COOKIE[lang].inc.php") : glob("lang/*.inc.php")) as $filename) {
$messages = $messages_all; $messages = $messages_all;
preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", file_get_contents($filename), $matches, PREG_SET_ORDER); preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", file_get_contents($filename), $matches, PREG_SET_ORDER);
$s = "<?php\n\$translations['" . basename($filename, ".inc.php") . "'] = array(\n"; $s = "<?php\n\$translations = array(\n";
foreach ($matches as $match) { foreach ($matches as $match) {
if (isset($messages[$match[3]])) { if (isset($messages[$match[3]])) {
$s .= "$match[1]$match[2],\n"; $s .= "$match[1]$match[2],\n";

View file

@ -1,5 +1,5 @@
<?php <?php
$translations['cs'] = array( $translations = array(
'Login' => 'Přihlásit se', 'Login' => 'Přihlásit se',
'phpMinAdmin' => 'phpMinAdmin', 'phpMinAdmin' => 'phpMinAdmin',
'Logout successful.' => 'Odhlášení proběhlo v pořádku.', 'Logout successful.' => 'Odhlášení proběhlo v pořádku.',

View file

@ -1,5 +1,5 @@
<?php <?php
$translations['en'] = array( $translations = array(
'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'), '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'), '%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.'), 'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'),

View file

@ -1,5 +1,5 @@
<?php <?php
$translations['sk'] = array( $translations = array(
'Login' => 'Prihlásiť sa', 'Login' => 'Prihlásiť sa',
'phpMinAdmin' => 'phpMinAdmin', 'phpMinAdmin' => 'phpMinAdmin',
'Logout successful.' => 'Odhlásenie prebehlo v poriadku', 'Logout successful.' => 'Odhlásenie prebehlo v poriadku',