2012-05-26 06:21:31 +00:00
|
|
|
#!/usr/bin/env php
|
2007-07-05 10:46:44 +00:00
|
|
|
<?php
|
2009-08-28 10:56:54 +00:00
|
|
|
error_reporting(6135); // errors and warnings
|
2009-09-10 19:05:27 +00:00
|
|
|
unset($_COOKIE["adminer_lang"]);
|
|
|
|
$_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
|
|
|
|
if (isset($_SESSION["lang"])) {
|
2009-06-13 20:55:19 +00:00
|
|
|
include dirname(__FILE__) . "/adminer/include/lang.inc.php";
|
2012-10-04 07:25:22 +00:00
|
|
|
if (isset($_SERVER["argv"][2]) || (!isset($langs[$_SESSION["lang"]]) && $_SESSION["lang"] != "xx")) {
|
2009-07-22 11:51:25 +00:00
|
|
|
echo "Usage: php lang.php [lang]\nPurpose: Update adminer/lang/*.inc.php from source code messages.\n";
|
2007-07-26 16:47:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
|
2007-07-09 06:12:22 +00:00
|
|
|
$messages_all = array();
|
2009-07-22 11:51:25 +00:00
|
|
|
foreach (array_merge(
|
|
|
|
glob(dirname(__FILE__) . "/adminer/*.php"),
|
|
|
|
glob(dirname(__FILE__) . "/adminer/include/*.php"),
|
2010-04-21 12:01:32 +00:00
|
|
|
glob(dirname(__FILE__) . "/adminer/drivers/*.php"),
|
2009-07-22 11:51:25 +00:00
|
|
|
glob(dirname(__FILE__) . "/editor/*.php"),
|
2009-08-21 16:14:00 +00:00
|
|
|
glob(dirname(__FILE__) . "/editor/include/*.php")
|
|
|
|
) as $filename) {
|
2009-07-22 11:51:25 +00:00
|
|
|
$file = file_get_contents($filename);
|
|
|
|
if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
|
|
|
|
$messages_all += array_combine($matches[1], $matches[2]);
|
2007-07-09 15:28:37 +00:00
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
|
2009-09-10 19:05:27 +00:00
|
|
|
foreach (glob(dirname(__FILE__) . "/adminer/lang/" . ($_SESSION["lang"] ? $_SESSION["lang"] : "*") . ".inc.php") as $filename) {
|
2007-07-09 06:12:22 +00:00
|
|
|
$messages = $messages_all;
|
2009-07-03 09:47:29 +00:00
|
|
|
$file = file_get_contents($filename);
|
2010-10-16 20:36:01 +00:00
|
|
|
$file = str_replace("\r", "", $file);
|
2010-10-17 19:12:37 +00:00
|
|
|
preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $file, $matches, PREG_SET_ORDER);
|
2007-08-07 15:27:51 +00:00
|
|
|
$s = "";
|
2007-07-05 10:46:44 +00:00
|
|
|
foreach ($matches as $match) {
|
|
|
|
if (isset($messages[$match[3]])) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// keep current messages
|
2007-07-05 10:46:44 +00:00
|
|
|
$s .= "$match[1]$match[2],\n";
|
|
|
|
unset($messages[$match[3]]);
|
|
|
|
} else {
|
2009-06-21 23:20:32 +00:00
|
|
|
// comment deprecated messages
|
2007-07-05 10:46:44 +00:00
|
|
|
$s .= "$match[1]// $match[2],\n";
|
|
|
|
}
|
|
|
|
}
|
2010-10-22 14:27:16 +00:00
|
|
|
if ($messages) {
|
2010-11-12 17:00:19 +00:00
|
|
|
if (basename($filename) != "en.inc.php") {
|
|
|
|
$s .= "\n";
|
|
|
|
}
|
2010-10-22 14:27:16 +00:00
|
|
|
foreach ($messages as $idf => $val) {
|
|
|
|
// add new messages
|
|
|
|
if ($val == "," && strpos($idf, "%d")) {
|
|
|
|
$s .= "\t$idf => array(),\n";
|
|
|
|
} elseif (basename($filename) != "en.inc.php") {
|
|
|
|
$s .= "\t$idf => null,\n";
|
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
2009-07-03 09:47:29 +00:00
|
|
|
$s = "<?php\n\$translations = array(\n$s);\n";
|
|
|
|
if ($s != $file) {
|
|
|
|
fwrite(fopen($filename, "w"), $s); // file_put_contents() since PHP 5
|
|
|
|
echo "$filename updated.\n";
|
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|