-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate.php
executable file
·76 lines (69 loc) · 1.96 KB
/
generate.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/php
<?php
$findcmd = 'find ./projects/ -name *.json -not ' .
'-name qqq.json -not -name raw.json -not -name frequency.json';
$json_files = explode("\n", `$findcmd`);
$override_lang = array(
'ko' => 'ko_KR',
'de' => 'de_DE',
'fr' => 'fr_FR',
'es' => 'es_ES',
'cs' => 'cs_CS',
);
foreach ($json_files as $filename) {
if (!file_exists($filename)) {
echo("File does not exist: $filename\n");
continue;
}
$part = explode("/", $filename);
$project = $part[2];
$app = $part[3];
$lang = $part[4];
$lang = explode('.', $lang)[0];
if (isset($override_lang[$lang])) {
$lang = $override_lang[$lang];
} else {
$lang_parts = explode('-', $lang);
$lang = strtolower($lang_parts[0]);
if (count($lang_parts) == 3) {
$lang .= "_".strtoupper($lang_parts[1]);
$lang .= "_".ucfirst($lang_parts[2]);
} else if (count($lang_parts) == 2) {
if (strlen($lang_parts[1]) == 2) {
$lang .= "_".strtoupper($lang_parts[1]);
} else {
$lang .= "_".ucfirst($lang_parts[1]);
}
}
}
$classname = ucfirst($project).ucfirst($app).ucfirst($lang);
$classname = str_replace('_', '', $classname);
$cmd = ['./bin/translatewiki',
'generate',
'--source',
$filename,
'--class',
$classname,
'--locale',
$lang,
'--project',
$project.'/'.$app,
'--out',
"./src/translations/$classname.php"
];
$args = array();
foreach($cmd as $arg) {
$args[] = escapeshellarg($arg);
}
$cmd = join(" ", $args);
$return_code = null;
$output = array();
echo "\nrun: $cmd\n\n";
exec($cmd, $output, $return_code);
foreach($output as $line) {
echo $line."\n";
}
if ($return_code) {
echo "ERROR: $return_code";
}
}