-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlangcomp.php
220 lines (201 loc) · 6.42 KB
/
langcomp.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<html>
<head><title>语言比较</title></head>
<body>
<?php
class LangDiff
{
public $src_only;
public $dst_only;
public $same;
public $diff;
public function LangDiff()
{
$this->src_only=array();
$this->dst_only=array();
$this->same=array();
$this->diff=array();
}
public function stack($lang_diff)
{
$this->src_only = array_merge($this->src_only, $lang_diff->src_only);
$this->dst_only = array_merge($this->dst_only, $lang_diff->dst_only);
$this->same = array_merge($this->same, $lang_diff->same);
$this->diff = array_merge($this->diff, $lang_diff->diff);
}
}
function keyAmount($arr)
{
$amount = 0;
if (is_array($arr)==false) return 1;
foreach ($arr as $key => $value)
{
if ( is_array($arr[$key]) )
{
$amount+=keyAmount($arr[$key]);
}
else
{
$amount++;
}
}
return $amount;
}
function keyList($arr, $common_name, &$list)
{
if (is_array($arr)==false) return;
foreach ($arr as $key => $value)
{
if ( is_array($arr[$key]) )
{
keyList( $arr[$key], $common_name."[".$key."]", $list );
}
else
{
$list[]=$common_name."[".$key."]";
}
}
}
function compArray($src, $dst, $common_name="")
{
$lang_diff = new LangDiff();
//检测源语言中独有的键
foreach ($src as $key => $value)
{
if ( !array_key_exists($key, $dst) )
{
$lang_diff->src_only[] = $common_name."[".$key."]";
continue;
}
if ( is_array($src[$key]) && is_array($dst[$key]) )
{
$lang_diff->stack( compArray($src[$key], $dst[$key], $common_name."[".$key."]") );
}
else if ( is_array($src[$key])==true && is_array($dst[$key])==false )
{
}
else if ( is_array($src[$key])==false && is_array($dst[$key])==true )
{
}
else
{
if ( $src[$key] == $dst[$key] )
{
$lang_diff->same[] = $common_name."[".$key."]";
}
else
{
$lang_diff->diff[] = $common_name."[".$key."]";
}
}
}
//检测目标语言中独有的键
foreach ($dst as $key => $value)
{
if ( !array_key_exists($key, $src) )
{
//$lang_diff->dst_only[] = $common_name."[".$key."]";
$addition_keys = array();
keyList( $dst[$key], $common_name."[".$key."]", $addition_keys );
array_merge($lang_diff->dst_only, $addition_keys);
}
}
return $lang_diff;
}
function comp($src_lang, $dst_lang)
{
$pages=array(); //页面名称
$pages['admin']="ADMIN";
$pages['banner']="BANNER";
$pages['faq']="FAQ";
$pages['fleet']="FLEET";
$pages['ingame']="INGAME";
$pages['install']="INSTALL";
$pages['l18n']="L18N";
$pages['public']="PUBLIC";
$pages['tech']="TECH";
$output="<table border=1>";
$output.="<tr align=center><td>文件名</td><td>已翻译</td><td>总条目数</td><td>完成进度</td><td>备注</td></tr>";
$total_diff = 0;
$total_amount = 0;
foreach ($pages as $pagekey => $pagename)
{
unset($LNG);
$LNG = array();
unset($SRC_LNG);
$SRC_LNG=array();
include("language/$src_lang/$pagename.php");
foreach ($LNG as $key => $value){
$SRC_LNG[$key]=$value;
}
unset($DST_LNG);
$DST_LNG=array();
include("language/$dst_lang/$pagename.php");
@include("language/$dst_lang/ignore/$pagename.php");
foreach ($LNG as $key => $value){
$DST_LNG[$key]=$value;
}
$diff = compArray($SRC_LNG, $DST_LNG);
$srcKeyList = array();
$dstKeyList = array();
keyList($SRC_LNG, "", $srcKeyList);
keyList($DST_LNG, "", $dstKeyList);
//echo "$pagename.php"."";
//echo "总词数:".keyAmount($SRC_LNG)." : ".keyAmount($DST_LNG)."<br/>";
//echo "总词数:".count($srcKeyList)." : ".count($dstKeyList)."<br/>";
//echo $src_lang."特有:".count($diff->src_only)."<br/>";
//echo $dst_lang."特有:".count($diff->dst_only)."<br/>";
//echo "相 同:".count($diff->same)."<br/>";
//echo "不 同:".count($diff->diff)."<br/><br/>";
$diffcounter = count($diff->diff);
$amount = count($srcKeyList);
$percentage = (int)( $diffcounter * 10000 / $amount );
$percentage = ($percentage/100)."%";
//echo "完成进度: ".count($diff->diff)."/".count($srcKeyList)."(".$percentage."%)"."<br/>";
$delta = count($diff->same);
$status="";
$bgcolor = "";
if ($delta == 0)
{
$status.="翻译完成";
$bgcolor = "bgcolor=green";
}
else if ($delta>30)
{
$status.="未翻译项过多";
}
else
{
$status.="未翻译项如下:";
foreach ($diff->same as $key => $value)
{
$status.="<br/>".$value;
}
}
$output.="<tr ".$bgcolor."><td>".$pagename.".php</td><td align=right>".$diffcounter."</td><td align=right>".$amount."</td><td align=right>".$percentage."</td><td>".$status."</td></tr>";
$total_diff += $diffcounter;
$total_amount += $amount;
}
$percentage = (int)( $total_diff * 10000 / $total_amount );
$percentage= ($percentage/100)."%";
$output.="<tr><td>总量</td><td align=right>".$total_diff."</td><td align=right>".$total_amount."</td><td align=right>".$percentage."</td></tr>";
$output.="</table>";
return $output;
}
//以下是页面部分
$src_lang=isset($_POST['srclang'])?$_POST['srclang']:"";
$dst_lang=isset($_POST['dstlang'])?$_POST['dstlang']:"";
if ($src_lang=="" || $dst_lang=="") { ?>
<form action="langcomp.php" method="post">
<input type="text" name="srclang" value="en" />
<input type="text" name="dstlang" value="cn" />
<input type="submit" />
</form>
<?php
}
else { ?>
<?php
echo comp($src_lang, $dst_lang);
}
?>
</body>
</html>