]> git.joonet.de Git - adminer.git/commitdiff
lang.php: Add translation of plugin description
authorJakub Vrana <jakub@vrana.cz>
Mon, 7 Apr 2025 16:22:59 +0000 (18:22 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 7 Apr 2025 16:26:31 +0000 (18:26 +0200)
lang.php

index 0bdda746be608dd8a149dbe5c00fedee8e33e1ab..388dbc6b8c7ecc19c91c8bf68d945613177b018c 100755 (executable)
--- a/lang.php
+++ b/lang.php
@@ -22,7 +22,7 @@ foreach (
        ) as $include
 ) {
        $file = file_get_contents($include);
-       if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
+       if (preg_match_all("~[^>]lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
                $messages_all += array_combine($matches[1], $matches[2]);
        }
 }
@@ -33,8 +33,9 @@ foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.ph
        if ($lang != "xx") {
                foreach (glob(__DIR__ . "/plugins/*.php") as $filename) {
                        $file = file_get_contents($filename);
-                       if (preg_match_all("~\\\$this->lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) {
-                               $messages = array_combine($matches[1], $matches[2]);
+                       if (preg_match('~extends Adminer\\\\Plugin~', $file)) {
+                               preg_match_all("~\\\$this->lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches);
+                               $messages = array("''" => "") + array_combine($matches[1], $matches[2]);
                                $file = preg_replace("~(static \\\$translations = array\\((?!.*'$lang').*?)\t\\);~s", "\\1\t\t'$lang' => array(\n\t\t),\n\t);", $file);
                                file_put_contents($filename, $file);
                                update_translations($lang, $messages, $filename, "~(static \\\$translations = array\\(.*'$lang' => array\\(\n)(.*)(?=^\t\t\\),)~msU", "\t\t\t");
@@ -86,6 +87,7 @@ function update_translations($lang, $messages, $filename, $pattern, $tabs = "\t"
                return $prefix . $s;
        }, $file, -1, $count, PREG_OFFSET_CAPTURE);
        if ($s != $file) {
+               $s = str_replace("array(\n\t\t\t'' => null,\n\t\t),", "array('' => null),", $s);
                file_put_contents($filename, $s);
                echo "$filename updated.\n";
        }