-
Notifications
You must be signed in to change notification settings - Fork 3
/
lang-translations.php
63 lines (61 loc) · 2.07 KB
/
lang-translations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env php
<?php
error_reporting(6135); // errors and warnings
unset($_COOKIE["sigal_lang"]);
$_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
if (isset($_SESSION["lang"])) {
//include dirname(__FILE__) . "/langs/*.lang.php";
if (isset($_SERVER["argv"][2]) || (!isset($langs[$_SESSION["lang"]]) && $_SESSION["lang"] != "xx")) {
echo "Usage: php lang.php [lang]\nPurpose: Update lang/*.inc.php from source code messages.\n";
exit(1);
}
}
$messages_all = array();
foreach (array_merge(
//glob(dirname(__FILE__) . "/dir/*.php"),
glob(dirname(__FILE__) . "/sigal.class.php"),
glob(dirname(__FILE__) . "/functions.php"),
glob(dirname(__FILE__) . "/index.php")
) as $filename) {
$file = file_get_contents($filename);
if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
$messages_all += array_combine($matches[1], $matches[2]);
}
}
foreach (glob(dirname(__FILE__) . "/lang/" . ($_SESSION["lang"] ? $_SESSION["lang"] : "*") . ".lang.php") as $filename) {
$messages = $messages_all;
$file = file_get_contents($filename);
$file = str_replace("\r", "", $file);
preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $file, $matches, PREG_SET_ORDER);
$s = "";
foreach ($matches as $match) {
if (isset($messages[$match[3]])) {
// keep current messages
$s .= "$match[1]$match[2],\n";
unset($messages[$match[3]]);
} else {
// comment deprecated messages
$s .= "$match[1]// $match[2],\n";
}
}
if ($messages) {
if (basename($filename) != "en.lang.php") {
$s .= "\n";
}
foreach ($messages as $idf => $val) {
//echo $idf.'=>'.$val;
// add new messages
if ($val == "," && strpos($idf, "%d")) {
$s .= "\t$idf => array(),\n";
} elseif (basename($filename) != "en.lang.php") {
$s .= "\t$idf => null,\n";
}
}
}
$id = substr(basename($filename), 0, 2);
$s = "<?php\n\$translations['".$id."'] = array(\n$s);\n?>\n";
if ($s != $file) {
file_put_contents($filename, $s);
echo "$filename updated.\n";
}
}