mirrored from git://git.rockbox.org/translate.git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
executable file
·206 lines (188 loc) · 7.93 KB
/
update.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
#!/usr/bin/php -q
<?php
/************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* Copyright (C) 2010 Jonas Häggqvist
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
**************************************************************************/
error_reporting(E_ALL);
require_once('common.php');
chdir(dirname(__FILE__));
function update_langs() {
$fp = fopen(VERSIONS, 'w');
foreach(glob('rockbox/apps/lang/*.lang') as $lang) {
$gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H -1 %s",
"apps/lang/" . basename($lang)));
$line = sprintf("%s:%s\n", basename($lang, '.lang'), trim($gitstr));
fwrite($fp, $line);
}
fclose($fp);
return true;
}
function genstats() {
$langs = array();
foreach(file(VERSIONS) as $line) {
list($lang, $version) = explode(":", trim($line));
$langs[$lang] = $version;
}
$stats = array();
foreach($langs as $lang => $rev) {
$foo = array();
$err = 0;
$cmd = sprintf("%s -s rockbox/tools/updatelang rockbox/apps/lang/english.lang rockbox/apps/lang/%s.lang -", PERL, $lang);
$output = shell_exec($cmd);
// print("$ $cmd\n");
// printf("%s\n", $output);
file_put_contents(sprintf("scratch/%s.lang.update", $lang), $output);
list($lastrev, $lastupdate) = getlastupdated($lang);
$stat = array('name' => $lang, 'total' => 0, 'error' => 0, 'missing' => 0, 'desc' => 0, 'source' => 0, 'dest' => 0, 'destdup' => 0, 'voice' => 0, 'voicedup' => 0, 'last_update' => $lastupdate, 'last_update_rev' => $lastrev);
foreach(explode("\n", $output) as $line) {
if (preg_match('/### This phrase is missing entirely/', $line)) {
$stat['missing']++;
$err++;
} elseif (preg_match("/### The <source> section for '.*' is missing/", $line) ||
preg_match("/### The <source> section for '.*' differs/", $line)) {
$stat['source']++;
$err++;
} elseif (preg_match("/### The 'desc' field for '.*' differs/", $line) ||
preg_match("/### The 'user' field for '.*' differs/", $line)) {
$stat['desc']++;
$err++;
} elseif (preg_match("/### The <dest> section for '.*' is missing/", $line) ||
preg_match("/### The <dest> section for '.*' is blank/", $line) ||
preg_match("/### The <dest> section for '.*' is not blank/", $line) ||
preg_match("/### The <dest> section for '.*' has illegal/", $line) ||
preg_match("/### The <dest> section for '.*' has incorrect/", $line)) {
$stat['dest']++;
$err++;
} elseif (preg_match("/### The <dest> section for '.*' is identica/", $line)) {
$stat['destdup']++;
$err++;
} elseif (preg_match("/### The <voice> section for '.*' is missing/", $line) ||
preg_match("/### The <voice> section for '.*' is blank/", $line) ||
preg_match("/### The <voice> section for '.*' is not blank/", $line) ||
preg_match("/### The <voice> section for '.*' has some suspicious/", $line) ||
preg_match("/### The <voice> section for '.*' has ellipses/", $line)) {
$stat['voice']++;
$err++;
} elseif (preg_match("/### The <voice> section for '.*' is identical/", $line)) {
$stat['voicedup']++;
$err++;
} elseif (preg_match('/<\/phrase>/', $line)) {
$stat['total']++;
$err = 0;
} elseif (preg_match('/id: (.*)/', $line, $matches)) {
$foo[$matches[1]] = $err;
}
}
foreach($foo as $id => $val) {
if ($val > 0) {
$stat['error']++;
}
}
$stats[$lang] = $stat;
}
/* Read in old language stats */
$oldstats = get_stats();
/* Write out new stats */
file_put_contents(STATS, serialize($stats));
/* Re-read stats */
$stats = get_stats();
/* Read in maintainers list */
$maintainers = maintainerinfo();
if ($maintainers !== FALSE) {
/* Find out if anything has changed */
foreach($stats['langstats'] as $lang => &$info) {
if (isset($maintainers[$lang])) {
$oldinfo = $oldstats['langstats'][$lang];
// $info['percentage']--; // XXX for testing only.
foreach($maintainers[$lang] as $id => $email) {
if ($info['percentage'] < $oldinfo['percentage']) {
$headers = sprintf("From: %s", OUTBOUND_EMAIL);
$subject = sprintf("Rockbox '%s' translation needs updating\n", $lang);
$msg = sprintf("
You are receiving this as you are listed as a maintainer for the
'%s' Rockbox translation. Please contact the admins if this is
in error.
Current translation status as of %s:
percent complete: %s
missing strings: %s
source changed: %s
description changed: %s
destination issues: %s
voice issues: %s
same as english: %s
Please submit an update at your convenience!
",
$lang, substr($stats['langstats']['english']['last_update_rev'], 0, 10),
$info['percentage'], $info['missing'], $info['source'],
$info['desc'], $info['dest'], $info['voice'], $info['destdup'] + $info['voicedup']);
mail($email, $subject, $msg, $headers);
}
}
}
}
}
return true;
}
function getlastupdated($lang) {
$retries = 0;
while ($retries < 5) {
try {
$gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H,%%ct -200 apps/lang/%s.lang", $lang));
$line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr);
$retries = 100;
}
catch (Exception $e) {
$retries++;
printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage());
if ($retries > 5) die("Cannot succeed :(");
}
}
$ignorehash = explode("\n", file_get_contents('ignoredhash.list'));
foreach(preg_split('(\n\r|\r\n|\r|\n)', $gitstr) as $logentry) {
list($rev, $date) = explode(",", trim($logentry));
if(!in_array($rev, $ignorehash)) {
return array($rev, $date);
}
}
return array(0, 0);
}
function update_flags() {
$languageinfo = languageinfo();
$path = "e/e6";
if (!file_exists('flags')) {
mkdir('flags');
}
foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) {
if (!file_exists('flags/'.$size)) {
mkdir('flags/'.$size);
}
foreach($languageinfo as $lang) {
$dest = sprintf("flags/%d/%s.png", $size, $lang['flag']);
if (!file_exists($dest)) {
$src = sprintf('http://upload.wikimedia.org/wikipedia/commons/thumb/%3$s/Flag_of_%2$s.svg/%1$dpx-Flag_of_%2$s.svg.png', $size, $lang['flag'], $path);
printf("%s \n --> %s\n", $src, $dest);
copy($src, $dest);
sleep(1.0); # Don't be rude
}
}
}
}
update_langs();
genstats();
update_flags();
?>