-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxl.copy.help
More file actions
70 lines (67 loc) · 2.17 KB
/
xl.copy.help
File metadata and controls
70 lines (67 loc) · 2.17 KB
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
#!/usr/bin/php -q
<?PHP
/*
xl.copy.help - copy new help sections and remove unused sections in foreign helptext files
Copyright @2024, Bergware International.
*/
$rootdir = "/boot/unraid/languages";
$native = "$rootdir/lang-en_US/helptext.txt";
$foreign = array_filter(glob("$rootdir/*",GLOB_ONLYDIR|GLOB_NOSORT),'foreign');
function foreign($lang) {
return strpos($lang,'en_US')===false;
}
function escapeQuotes($text,$in=1) {
switch ($in) {
case 1: return str_replace(["\"\n",'"'],["\" \n",'\"'],$text);
case 0: return str_replace('"','\"',$text);
}
}
function parse_help_file($file) {
return file_exists($file) ? parse_ini_string(preg_replace(['/^:(.+_help(_\d{8})?):$/m','/^:end$/m'],['_$1="','"'],escapeQuotes(file_get_contents($file)))) : [];
}
function base($file) {
global $plugins;
return str_replace("$plugins/",'',$file);
}
$name = basename($native);
$source = parse_help_file($native);
// remove unused entries
foreach ($foreign as $language) {
$output = "$language/$name";
echo "Parsing: $output",str_repeat(' ',120-strlen($output)),"\r";
$target = parse_help_file($output);
$file = base($output);
$void = [];
// make list of entries to remove
foreach ($target as $row => $text) if (!isset($source[$row])) {
$label = substr($row,1);
$void[] = "/^:$label:\\\$/,/^:end\\\$/d";
}
$size = count($void);
if ($size) {
$void = array_unique($void,SORT_STRING);
echo "\nUpdating (delete): $output ($size)\n";
foreach ($void as $row) exec("sed -ri \"$row\" $output");
}
}
// add new entries
foreach ($foreign as $language) {
$output = "$language/$name";
echo "Parsing: $output",str_repeat(' ',120-strlen($output)),"\r";
$target = parse_help_file($output);
$new = [];
// make list of entries to add
foreach ($source as $row => $text) if (!isset($target[$row])) {
$label = substr($row,1);
$new[] = "\n:$label:".escapeQuotes($text,0).":end";
}
$size = count($new);
if ($size) {
echo "\nUpdating (add): $output ($size)\n";
$date = date('Y-m-d');
exec("echo -e \"\n; New entries ($size) - $date\" >>$output");
foreach ($new as $row) exec("echo -e \"$row\" >>$output");
}
}
echo str_repeat(' ',120)."\r";
?>