-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathcheck-langs.php
56 lines (42 loc) · 1.36 KB
/
check-langs.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
<?php
if ($argc != 2 || (isset($argv[1]) && in_array($argv[1], array('--help', '-h')))) {
echo "Check language files for missing/redundant keys\n\n";
echo "Usage: {$argv[0]} <lang>\n";
echo "Alternative usage: {$argv[0]} all\n";
exit;
}
chdir('../phpdotnet/phd/data/langs/');
if ($argv[1] === 'all') {
$languages = glob('*.ini');
unset($languages[array_search('en.ini', $languages)]);
} else {
$languages[] = $argv[1] . '.ini';
}
$englishKeys = array_keys(parse_ini_file('en.ini'));
foreach($languages as $language) {
check_language($language, $englishKeys);
}
function check_language($path, $englishKeys) {
$language = substr($path, 0, -4);
if (!file_exists($path)) {
exit("Unknown language: $language\n");
}
$languageKeys = array_keys(parse_ini_file($path));
$missing = array_diff($englishKeys, $languageKeys);
$redundant = array_diff($languageKeys, $englishKeys);
echo "Checking $language...";
if (!$missing && !$redundant) {
echo " OK\n";
}
if ($missing) {
echo "\n\tMissing (" . sizeof($missing) . "):\n";
foreach ($missing as $text) {
echo "\t\t$text\n";
}
}
if ($redundant) {
$placing = $missing ? "\t" : "\n\t";
$redundant = implode(", ", $redundant);
echo "{$placing}Redundant: $redundant\n";
}
}