2007-07-05 10:46:44 +00:00
|
|
|
<?php
|
|
|
|
if ($_SERVER["argc"] > 1) {
|
|
|
|
echo "Usage: php _lang.php\nPurpose: Update lang.inc.php from source code messages.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-07-09 06:12:22 +00:00
|
|
|
$messages_all = array();
|
2007-07-05 10:46:44 +00:00
|
|
|
foreach (glob("*.php") as $filename) {
|
|
|
|
$file = file_get_contents($filename);
|
2007-07-10 18:53:35 +00:00
|
|
|
if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) {
|
2007-07-09 15:28:37 +00:00
|
|
|
$messages_all += array_combine($matches[1], $matches[2]);
|
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$file = file_get_contents("lang.inc.php");
|
2007-07-17 14:04:29 +00:00
|
|
|
preg_match_all("~\n\t'(.*)' => array\\(\n(.*\n)\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
|
2007-07-09 06:12:22 +00:00
|
|
|
foreach (array_reverse($translations[2], true) as $key => $translation) {
|
|
|
|
$messages = $messages_all;
|
2007-07-10 18:53:35 +00:00
|
|
|
preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
|
2007-07-05 10:46:44 +00:00
|
|
|
$s = "";
|
|
|
|
foreach ($matches as $match) {
|
|
|
|
if (isset($messages[$match[3]])) {
|
|
|
|
$s .= "$match[1]$match[2],\n";
|
|
|
|
unset($messages[$match[3]]);
|
|
|
|
} else {
|
|
|
|
$s .= "$match[1]// $match[2],\n";
|
|
|
|
}
|
|
|
|
}
|
2007-07-09 15:28:37 +00:00
|
|
|
foreach($messages as $idf => $val) {
|
2007-07-10 11:37:21 +00:00
|
|
|
if ($val == "," && strpos($idf, "%d")) {
|
2007-07-17 14:04:29 +00:00
|
|
|
$s .= "\t\t$idf => array(),\n";
|
2007-07-09 15:28:37 +00:00
|
|
|
} elseif ($translations[1][$key][0] != 'en') {
|
2007-07-17 14:04:29 +00:00
|
|
|
$s .= "\t\t$idf => '',\n";
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
$file = substr_replace($file, $s, $translation[1], strlen($translation[0]));
|
|
|
|
}
|
|
|
|
file_put_contents("lang.inc.php", $file);
|
2007-07-15 10:50:45 +00:00
|
|
|
echo "lang.inc.php modified.\n";
|