forked from BRIGADA/pandora-nashira-rus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.php
61 lines (54 loc) · 1.72 KB
/
build.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
<?php
@mkdir('build');
$dh = opendir('.');
$ta = 0;
$tt = 0;
while (($fn = readdir($dh)) !== false) {
if (fnmatch("*.xml.txt", $fn)) {
$fi = pathinfo($fn, PATHINFO_FILENAME);
printf("%24s :", $fi);
$f = file_get_contents($fn);
$d = explode("\n\n---\n\n", $f);
$o = array();
$ct = 0;
$o[] = '<?xml version="1.0" encoding="utf-8"?>';
$o[] = '<language>';
foreach ($d as $e) {
$r = explode("\n\n", $e);
if ($r[1] != $r[2]) {
$ct++;
}
$o[] = "\t" . '<entry name="' . $r[0] . '" value="' . encode($r[2]) . '"/>';
}
$o[] = '</language>';
$o[] = "\n";
file_put_contents('build' . DIRECTORY_SEPARATOR . $fi, implode("\n", $o));
if (count($d)) {
printf(" %u/%u (%u%%)\n", $ct, count($d), 100 * $ct / count($d));
}
$ta += count($d);
$tt += $ct;
}
}
printf("-----------------------------------------------------------\n");
printf("%24s : %u/%u (%u%%)\n", 'Total', $tt, $ta, 100 * $tt / $ta);
function encode($str) {
$str = str_replace('ç', 's', $str);
$str = str_replace('é', 'e', $str);
$str = str_replace('ö', 'o', $str);
$str = str_replace('á', 'a', $str);
$str = str_replace('ä', 'a', $str);
$str = str_replace('"', '"', $str);
if(@iconv("UTF-8", "CP1251", $str) === FALSE) {
echo PHP_EOL;
$s = preg_split('//u', $str);
foreach($s as $i => $c) {
if(@iconv("UTF-8", "CP1251", $c) === FALSE){
echo "Bad character '{$c}' on {$i}: '", substr($str, $i - 20, 40),"'", PHP_EOL;
$s[$i] = '#';
}
}
$str = implode('', $s);
}
return iconv("CP1252", "UTF-8", iconv("UTF-8", "CP1251", $str));
}