Permalink
Browse files

Flatten $translations

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@290 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 81dbdda commit bba76d8df62a470ede281a3dc6e22b9eb1e3b43b jakubvrana committed Aug 4, 2007
Showing with 18 additions and 19 deletions.
  1. +12 −14 _compile.php
  2. +3 −2 _lang.php
  3. +1 −1 lang/cs.inc.php
  4. +1 −1 lang/en.inc.php
  5. +1 −1 lang/sk.inc.php
View
26 _compile.php
@@ -4,9 +4,9 @@ function add_apo_slashes($s) {
}
function remove_lang($match) {
- global $LANG, $translations;
+ global $translations;
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
- $s = ($translations[$LANG][$idf] ? $translations[$LANG][$idf] : $idf);
+ $s = ($translations[$idf] ? $translations[$idf] : $idf);
if ($match[3] == ",") {
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) {
if ($match[4] == './lang/$LANG.inc.php') {
- $return = "";
- if (!$_COOKIE["lang"]) {
- foreach (glob("./lang/*.inc.php") as $filename) {
- $match[4] = $filename;
- $return .= put_file($match);
- }
+ if ($_COOKIE["lang"]) {
+ return "";
}
- 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]);
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 @@ function put_file($match) {
if ($_SERVER["argc"] > 1) {
$_COOKIE["lang"] = $_SERVER["argv"][1];
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";
exit(1);
}
include "./lang/$_COOKIE[lang].inc.php";
}
-$filename = "phpMinAdmin.php";
+
+$filename = "phpMinAdmin" . ($_COOKIE["lang"] ? "-$_COOKIE[lang]" : "") . ".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);
if ($_COOKIE["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
View
5 _lang.php
@@ -1,8 +1,9 @@
<?php
+error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) {
$_COOKIE["lang"] = $_SERVER["argv"][1];
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";
exit(1);
}
@@ -19,7 +20,7 @@
foreach (($_COOKIE["lang"] ? array("lang/$_COOKIE[lang].inc.php") : glob("lang/*.inc.php")) as $filename) {
$messages = $messages_all;
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) {
if (isset($messages[$match[3]])) {
$s .= "$match[1]$match[2],\n";
View
2 lang/cs.inc.php
@@ -1,5 +1,5 @@
<?php
-$translations['cs'] = array(
+$translations = array(
'Login' => 'Přihlásit se',
'phpMinAdmin' => 'phpMinAdmin',
'Logout successful.' => 'Odhlášení proběhlo v pořádku.',
View
2 lang/en.inc.php
@@ -1,5 +1,5 @@
<?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.'),
'%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.'),
View
2 lang/sk.inc.php
@@ -1,5 +1,5 @@
<?php
-$translations['sk'] = array(
+$translations = array(
'Login' => 'Prihlásiť sa',
'phpMinAdmin' => 'phpMinAdmin',
'Logout successful.' => 'Odhlásenie prebehlo v poriadku',

0 comments on commit bba76d8

Please sign in to comment.