]> git.joonet.de Git - adminer.git/commitdiff
sprintf() in lang()
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 9 Jul 2007 15:28:37 +0000 (15:28 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 9 Jul 2007 15:28:37 +0000 (15:28 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@84 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
_lang.php
design.inc.php
lang.inc.php

index 5be824eebc6f1c8337241f4c7cfec1078b4ea384..627e78b84b1db0db6390b344f995fe1c88510ceb 100644 (file)
@@ -1,11 +1,25 @@
 <?php
+function add_apo_slashes($s) {
+       return addcslashes($s, "\\'");
+}
+
 function remove_lang($match) {
-       $s = lang(strtr($match[2], array("\\'" => "'", "\\\\" => "\\")));
-       return ($match[1] && $match[3] ? $s : "$match[1]'" . addcslashes($s, "\\'") . "'$match[3]");
+       $s = lang(strtr($match[2], array("\\'" => "'", "\\\\" => "\\")), false);
+       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] && $match[4] ? $s : "$match[1]'" . add_apo_slashes($s) . "'$match[4]");
 }
 
 function put_file($match) {
        $return = file_get_contents($match[4]);
+       if ($match[4] == "./lang.inc.php") {
+               if (!$_SESSION["lang"]) {
+                       $return = str_replace("\tif (\$number === false && \$translation) {\n\t\treturn \$translation; // used in _compile.php\n\t}\n", "", $return);
+               } elseif (preg_match("~case '$_SESSION[lang]': (.*) break;~", $return, $match) || preg_match("~default: (.*)~", $return, $match)) {
+                       return "$match[1]\nfunction lang(\$ar, \$number) {\n\t$match[1]\n\treturn \$ar[\$pos];\n}\n$match[5]";
+               }
+       }
        $return = preg_replace("~\\?>\n?\$~", '', $return);
        if (substr_count($return, "<?php") <= substr_count($return, "?>") && !$match[5]) {
                $return .= "<?php\n";
@@ -32,11 +46,10 @@ $filename = "phpMinAdmin.php";
 $file = file_get_contents("index.php");
 if ($_SESSION["lang"]) {
        $filename = "phpMinAdmin-$_SESSION[lang].php";
-       $file = str_replace("include \"./lang.inc.php\";\n", "", $file);
 }
 $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
 if ($_SESSION["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 echo get_lang(); ?>", $_SESSION["lang"], $file);
 }
index f82324cb9e20dbfb9712bed52b6069802ab2eeb2..45a4c1abcd0f9587ca4b552708a4b6e823e53754 100644 (file)
--- a/_lang.php
+++ b/_lang.php
@@ -7,8 +7,9 @@ if ($_SERVER["argc"] > 1) {
 $messages_all = array();
 foreach (glob("*.php") as $filename) {
        $file = file_get_contents($filename);
-       preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')[),]~s", $file, $matches);
-       $messages_all += array_flip($matches[1]);
+       if (preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')([),])~", $file, $matches)) {
+               $messages_all += array_combine($matches[1], $matches[2]);
+       }
 }
 
 $file = file_get_contents("lang.inc.php");
@@ -25,9 +26,11 @@ foreach (array_reverse($translations[2], true) as $key => $translation) {
                        $s .= "$match[1]// $match[2],\n";
                }
        }
-       if ($translations[1][$key][0] != 'en') {
-               foreach($messages as $key => $val) {
-                       $s .= "\t\t\t$key => '',\n";
+       foreach($messages as $idf => $val) {
+               if ($val == ",") {
+                       $s .= "\t\t\t$idf => array(),\n";
+               } elseif ($translations[1][$key][0] != 'en') {
+                       $s .= "\t\t\t$idf => '',\n";
                }
        }
        $file = substr_replace($file, $s, $translation[1], strlen($translation[0]));
index 91cf1d7c789384002d6a3a1f81663cf0766dcc55..99d6c784fb598995df8e77e5795ca24c3ec2f78a 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 function page_header($title) {
+       global $LANG;
        header("Content-Type: text/html; charset=utf-8");
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo get_lang(); ?>">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $LANG; ?>">
 <head>
 <title><?php echo lang('phpMinAdmin') . " - $title"; ?></title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
index 644e6d009b78b9a1f29995a806c81eaad8b43a41..6e1d014a53612d2867612a83b38464760ea37dd6 100644 (file)
@@ -1,24 +1,11 @@
 <?php
-function get_lang() {
-       if (strlen($_SESSION["lang"])) {
-               return $_SESSION["lang"];
-       }
-       $langs = lang();
-       $return = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
-       if (!in_array($return, $langs)) { //! try next languages
-               $return = preg_replace('~-.*~', '', $return);
-               if (!in_array($return, $langs)) {
-                       $return = "en";
-               }
-       }
-       return $return;
-}
-
-function lang($idf = null) {
+function lang($idf = null, $number = null) {
+       global $LANG;
        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.'),
                ),
                'cs' => array(
                        'Login' => 'Přihlásit se',
@@ -110,22 +97,29 @@ function lang($idf = null) {
                        '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í',
                ),
        );
        if (!isset($idf)) {
                return array_keys($translations);
        }
-       $lang = get_lang();
-       $translation = $translations[$lang][$idf];
+       $translation = $translations[$LANG][$idf];
+       if ($number === false && $translation) {
+               return $translation; // used in _compile.php
+       }
        $args = func_get_args();
-       if (is_array($translation)) {
-               switch ($lang) {
-                       case 'cs': $pos = ($args[1] == 1 ? 0 : (!$args[1] || $args[1] >= 5 ? 2 : 1)); break;
-                       default: $pos = ($args[1] == 1 ? 0 : 1);
+       if (is_array($translation) && $translation) {
+               switch ($LANG) {
+                       case 'cs': $pos = ($number == 1 ? 0 : (!$number || $number >= 5 ? 2 : 1)); break;
+                       default: $pos = ($number == 1 ? 0 : 1);
                }
                $translation = $translation[$pos];
        }
-       $args[0] = (strlen($translation) ? $translation : $idf);
+       if ($translation) {
+               $args[0] = $translation;
+       }
        return call_user_func_array('sprintf', $args);
 }
 
@@ -141,3 +135,16 @@ function switch_lang() {
 if (isset($_GET["lang"])) {
        $_SESSION["lang"] = $_GET["lang"];
 }
+
+if (strlen($_SESSION["lang"])) {
+       $LANG = $_SESSION["lang"];
+} else {
+       $langs = lang();
+       $LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+       if (!in_array($LANG, $langs)) { //! try next languages
+               $LANG = preg_replace('~-.*~', '', $LANG);
+               if (!in_array($LANG, $langs)) {
+                       $LANG = "en";
+               }
+       }
+}