forked from AndroidIDEOfficial/AndroidIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings-check.php
157 lines (125 loc) · 3.77 KB
/
strings-check.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
#!/usr/bin/php -q
<?php
// Android translation helper tool
// cross checks two strings.xml files to find diffs
//
// usage: ./strings-check.php values/base.xml values-lang/translated.xml
//
// Written by Marcin Orlowski <mail (@) marcinorlowski (.) com>
//
// 2010-07-03: Initial release
// 2017-04-25: Code cleanup; Added exit code
class Convert {
public function XmlToArray( $n )
{
$xml_array = array();
$occurance = array();
foreach($n->childNodes as $nc) {
if (isset($occurance[$nc->nodeName])) {
$occurance[$nc->nodeName]++;
} else {
$occurance[$nc->nodeName] = 1;
}
}
foreach($n->childNodes as $nc) {
if( $nc->hasChildNodes() ) {
$childNodes = $nc->childNodes;
$children = $childNodes->length;
if ($children>1) {
$xml_array[$nc->nodeName][] = $this->XmlToArray($nc);
$counter = count($xml_array[$nc->nodeName])-1;
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][$counter]['attribute'][$attrs->item($k)->nodeName] = $attrs->item($k)->nodeValue;
}
//$counter++;
} else {
$xml_array[$nc->nodeName][]['cdata'] = $nc->nodeValue;
$counter = count($xml_array[$nc->nodeName])-1;
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][$counter]['attribute'][$attrs->item($k)->nodeName] = $attrs->item($k)->nodeValue;
}
}
} else {
if( $nc->hasAttributes() ) {
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][0]['attribute'][$attrs->item($k)->nodeName]= $attrs->item($k)->nodeValue;
}
}
}
}
return $xml_array;
}
public function GetLabels( $fileName )
{
$xml = new DOMDocument('1.0','UTF-8');
$xml->load( $fileName );
$data = $this->XmlToArray( $xml );
$result = array();
foreach( $data['resources'][0]['string'] AS $entry ) {
$tmp = sprintf("%s", trim($entry['attribute']['name']));
$result[$tmp] = $tmp;
}
return $result;
}
// class convert
}
if( $_SERVER['argc'] != 3 ) {
printf("Usage: %s strings-BASE.xml string-LANG.xml\n", $_SERVER['argv'][0] );
die( "*** Aborted\n");
}
$fileBase = $_SERVER['argv'][1];
$fileLang = $_SERVER['argv'][2];
if( file_exists( $fileBase ) == FALSE ) {
die( sprintf("*** Missing BASE file '%s'\n", $fileBase ));
}
if( file_exists( $fileLang ) == FALSE ) {
die( sprintf("*** Missing LANG file '%s'\n", $fileLang ) );
}
$convert = new Convert();
$dataLang = $convert->GetLabels( $fileLang );
$dataBase = $convert->GetLabels( $fileBase );
$cntLang = $cntBase = 0;
echo "\n";
// comparing
printf("Missing in LANG (You need to translate these)\n");
printf("File: %s\n", $fileLang);
printf("------------------------- BEGIN ----------------------\n");
foreach( $dataBase as $string ) {
if( !array_key_exists($string, $dataLang)) {
printf("%s\n", $string);
$cntLang++;
}
}
printf("-------------------------- END -----------------------\n");
echo "\n\n";
printf("Not present in BASE (you need to remove it from LANG)\n");
printf("File: %s\n", $fileBase);
printf("------------------------- BEGIN ----------------------\n");
foreach( $dataLang as $string ) {
if( !array_key_exists($string, $dataBase)) {
printf("%s\n", $string);
$cntBase++;
}
}
printf("-------------------------- END -----------------------\n");
echo "\n\nSummary\n----------------\n";
echo "BASE file: '{$fileBase}'\n";
echo "LANG file: '{$fileLang}'\n";
echo "\n";
$rc = 1;
if( ($cntLang == 0) && ($cntBase==0) ) {
echo "OK. Files seem to be up to date.\n";
$rc = 0;
} else {
if( $cntLang > 0 ) {
printf( "%4d missing strings.\n", $cntLang );
}
if( $cntBase > 0 ) {
printf("%4d orphaned strings.\n", $cntBase );
}
}
echo "\n";
exit($rc);