mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 07:36:44 +02:00
Generalize updating translations
This commit is contained in:
19
lang.php
19
lang.php
@@ -28,12 +28,18 @@ foreach (
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.php") as $filename) {
|
foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.php") as $filename) {
|
||||||
$messages = $messages_all;
|
$lang = basename($filename, ".inc.php");
|
||||||
|
update_translations($lang, $messages_all, $filename, '~(\$translations = array\(\n)(.*\n)(?=\);)~sU');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_translations($lang, $messages, $filename, $pattern) {
|
||||||
$file = file_get_contents($filename);
|
$file = file_get_contents($filename);
|
||||||
$file = str_replace("\r", "", $file);
|
$file = str_replace("\r", "", $file);
|
||||||
preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => (.*[^,\n])),?~m", $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
|
$s = preg_replace_callback($pattern, function ($match) use ($lang, $messages, $filename, $file) {
|
||||||
|
$prefix = $match[1][0];
|
||||||
|
$start = $match[2][1];
|
||||||
|
preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => (.*[^,\n])),?~m", $match[2][0], $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
|
||||||
$s = "";
|
$s = "";
|
||||||
$lang = basename($filename, ".inc.php");
|
|
||||||
$fullstop = ($lang == "bn" ? '।' : (preg_match('~^(ja|zh)~', $lang) ? '。' : ($lang == 'he' ? '[^.]' : '\.')));
|
$fullstop = ($lang == "bn" ? '।' : (preg_match('~^(ja|zh)~', $lang) ? '。' : ($lang == 'he' ? '[^.]' : '\.')));
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
list(, list($indent), list($line, $offset), list($en), list($translation)) = $match;
|
list(, list($indent), list($line, $offset), list($en), list($translation)) = $match;
|
||||||
@@ -45,11 +51,11 @@ foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.ph
|
|||||||
//! check in array
|
//! check in array
|
||||||
if ($en != "','" && ($en_fullstop xor preg_match("~$fullstop'\)?\$~", $line))) {
|
if ($en != "','" && ($en_fullstop xor preg_match("~$fullstop'\)?\$~", $line))) {
|
||||||
if ($lang != ($en_fullstop ? "ja" : "he")) { // fullstop is optional in 'ja', forbidden in 'he'
|
if ($lang != ($en_fullstop ? "ja" : "he")) { // fullstop is optional in 'ja', forbidden in 'he'
|
||||||
echo "$filename:" . (substr_count($file, "\n", 0, $offset) + 1) . ":Not matching fullstop: $line\n";
|
echo "$filename:" . (substr_count($file, "\n", 0, $start + $offset) + 1) . ":Not matching fullstop: $line\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (preg_match('~%~', $en) xor preg_match('~%~', $translation)) {
|
if (preg_match('~%~', $en) xor preg_match('~%~', $translation)) {
|
||||||
echo "$filename:" . (substr_count($file, "\n", 0, $offset) + 1) . ":Not matching placeholder.\n";
|
echo "$filename:" . (substr_count($file, "\n", 0, $start + $offset) + 1) . ":Not matching placeholder.\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// comment deprecated messages
|
// comment deprecated messages
|
||||||
@@ -69,7 +75,8 @@ foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.ph
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$s = "<?php\nnamespace Adminer;\n\nLang::\$translations = array(\n$s);\n\n// run `php ../../lang.php $lang` to update this file\n";
|
return $prefix . $s;
|
||||||
|
}, $file, -1, $count, PREG_OFFSET_CAPTURE);
|
||||||
if ($s != $file) {
|
if ($s != $file) {
|
||||||
file_put_contents($filename, $s);
|
file_put_contents($filename, $s);
|
||||||
echo "$filename updated.\n";
|
echo "$filename updated.\n";
|
||||||
|
Reference in New Issue
Block a user