]> git.joonet.de Git - adminer.git/commitdiff
Allow using lang() in plugins
authorJakub Vrana <jakub@vrana.cz>
Sun, 28 Apr 2013 07:26:29 +0000 (00:26 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sun, 28 Apr 2013 15:17:40 +0000 (08:17 -0700)
changes.txt
compile.php

index c24b7e5879b5824100ce71588305a05837122a74..2f3890b95ad5309a57f27387c0e778de7bdf8336 100644 (file)
@@ -2,6 +2,7 @@ Adminer 3.7.0-dev:
 Allow more SQL files to be uploaded at the same time
 Print run time next to executed queries
 Disable SQL export when applying functions in select
+Allow using lang() in plugins (customization)
 MySQL: Optimize create table page and Editor navigation
 MySQL: Display bit type as binary number
 MySQL: Improve export of binary data types
index 39a2c59c392a40cb4003f44b6e08965a32569bda..71d2792fd97913de0dd05be7b51ccb06a3624c5f 100755 (executable)
@@ -42,6 +42,19 @@ function put_file($match) {
        }
        $return = file_get_contents(dirname(__FILE__) . "/$project/$match[2]");
        if (basename($match[2]) != "lang.inc.php" || !$_SESSION["lang"]) {
+               if (basename($match[2]) == "lang.inc.php") {
+                       $return = str_replace('function lang($idf, $number = null) {', 'function lang($idf, $number = null) {
+       if (is_string($idf)) { // compiled version uses numbers, string comes from a plugin
+               // English translation is closest to the original identifiers //! pluralized translations are not found
+               $pos = array_search($idf, get_translations("en")); //! this should be cached
+               if ($pos !== false) {
+                       $idf = $pos;
+               }
+       }', $return, $count);
+                       if (!$count) {
+                               echo "lang() not found\n";
+                       }
+               }
                $tokens = token_get_all($return); // to find out the last token
                return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
        } elseif (preg_match('~\\s*(\\$pos = (.+\n).+;)~sU', $return, $match2)) {
@@ -50,7 +63,7 @@ function put_file($match) {
        return '$_SESSION[lang]';
 }
 
-function lang(\$translation, \$number = 0) {
+function lang(\$translation, \$number = null) {
        if (is_array(\$translation)) {
                \$pos = $match2[2]\t\t\t: " . (preg_match("~\\\$LANG == '$_SESSION[lang]'.* \\? (.+)\n~U", $match2[1], $match3) ? $match3[1] : "1") . '
                );
@@ -62,7 +75,7 @@ function lang(\$translation, \$number = 0) {
 }
 ';
        } else {
-               echo "lang() not found\n";
+               echo "lang() \$pos not found\n";
        }
 }
 
@@ -126,13 +139,19 @@ if ($_SESSION["translations_version"] != ' . $translations_version . ') {
        $translations = array();
        $_SESSION["translations_version"] = ' . $translations_version . ';
 }
-if (!$translations) {
-       switch ($LANG) {' . $return . '
+
+function get_translations($lang) {
+       switch ($lang) {' . $return . '
        }
        $translations = array();
        foreach (explode("\n", lzw_decompress($compressed)) as $val) {
                $translations[] = (strpos($val, "\t") ? explode("\t", $val) : $val);
        }
+       return $translations;
+}
+
+if (!$translations) {
+       $translations = get_translations($LANG);
 }
 ';
 }