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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow,nosnippet">
<title>www.mageia.org report about differences between Transifex and our git repository</title>
<style>
html, body { margin: 0; padding: 0; font-family: Verdana, "Trebuchet MS", "Lucida Grande", "Lucida Sans", Verdana, Tahoma, Arial, sans-serif; }
table, th, td {
border:1px solid gray;
border-collapse:collapse;
}
th { text-align: left; }
td, th { font-size: 80%; padding: 0.3em; }
li { padding: 3px; }
#page { padding: 1em; position: absolute; top: 128px; }
.add { color: black; background: lightgrey; }
.bold { font-weight: bold; }
.stat { font-size: smaller; }
.italic { font-style:italic; }
</style>
</head>
<body class="contribute">
<header id="mgnavt">
<h1><a href="//www.mageia.org/">www.mageia.org</a> report about differences between Transifex and our git repository</h1>
<ul>
<li> </li>
</ul>
</header>
<div id="page">
<p>Progress report is available <a href="./report.php">here</a>.</p>
<?php
define('HLANG', TRUE);
include 'lib.php';
$errors = array(); // stored for error management ;)
$resource_type = 'Webpages'; // Webpages, Documentation, Cauldron
/**
* Transifex API implementation in php detailed on http://docs.transifex.com/developer/api/projects
*
* Returns $tx_result_array from Transifex request
*
* @param string $tx_request request
* @param string $project default project
*
* @return array
*/
function tx_call($tx_request, $project = 'project/mageia/')
{
global $errors;
$tx_url_prefix = "http://www.transifex.com/api/2/";
$tx_url = $tx_url_prefix . $project . $tx_request;
// create a new cURL resource
$curl_handle = curl_init();
// TX username and password
curl_setopt($curl_handle, CURLOPT_USERPWD, "filip_mageia:report");
// return, do not echo
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
// pass url
curl_setopt($curl_handle, CURLOPT_URL, $tx_url);
$tx_result = curl_exec($curl_handle);
curl_close($curl_handle);
$tx_result_array = json_decode($tx_result, TRUE);
$json_last_error = json_last_error();
if (JSON_ERROR_NONE !== $json_last_error) {
$error = "There was an error during API call to Transifex $tx_request ($json_last_error).";
$errors['tx_call'] = "$error Please reload the page or report this on mailing list.";
$tx_result_array = array();
}
if (FALSE === $tx_result) {
$errors['tx_call'] = "API call to Transifex $tx_request failed. Please reload the page or report this on mailing list.";
$tx_result_array = array();
}
return $tx_result_array;
}
/**
* Build Transifex and git links with numbers of untranslated strings
*
* Returns text string
*
* @param string $git_resource_name like 'about/constitution'
* @param string $language_code like 'sl'
* @param string $resource_type like 'Webpages'
* @param array $stat_data with numbers of untranslated strings
*
* @return string
*/
function build_links($git_resource_name, $language_code, $resource_type, $stat_data)
{
$tx_resource_name = str_replace('/', '-', $git_resource_name);
$locale_name = locale_underscore_to_hyphen($language_code);
if ('nav' == $git_resource_name) {
$git_link = sprintf('nav/tree/langs/%s.po', $locale_name);
} else {
$git_link = sprintf('www/tree/langs/%s/%s.po', $locale_name, $git_resource_name);
}
$links_and_num = "<a href=\"http://www.transifex.com/organization/MageiaLinux/dashboard/all_resources/";
$links_and_num .= "$language_code/#1/?s=$tx_resource_name&c=$resource_type\">Tx</a>: ";
$links_and_num .= $stat_data['tx_untran'];
$links_and_num .= ', <a href="http://gitweb.mageia.org/web/' . $git_link . '">git</a>: ';
$links_and_num .= $stat_data['git_untran'];
return $links_and_num;
}
$tx_resources = array();
// get resources data from TX
$tx_resources = tx_call("resources");
// create separate array ($tx_resources_info) and add statistics to it from TX
$tx_resources_info = array();
foreach ($tx_resources as $one_resource) {
$one_tx_resource_info = array();
$tx_resource_name = $one_resource['slug'];
$category = $one_resource['categories'][0];
// limit resource type only on one
if ($category == $resource_type) {
// add statistic
$tx_stat_for_resource = tx_call("resource/$tx_resource_name/stats");
$tx_resource_name = str_replace('page-', '', $tx_resource_name); // unify resource names
$one_resource['tx_resource_name'] = $tx_resource_name;
$one_resource['statistic'] = $tx_stat_for_resource;
$tx_resources_info[] = $one_resource;
}
}
// create array ($report) with statistics from git
$report = array();
$otherLangs = get_other_langs();
$enFiles = array_merge(array('../_nav/langs/en.pot'), get_lang_references('*.pot')); // added navigation file
foreach ($otherLangs as $l) {
foreach ($enFiles as $f) {
$references = '';
$resource = _extract_resource($f);
$langF = _po_file_switch($f, $l);
if (strstr($f, '../_nav/langs/en.') !== FALSE) {
$langF = '../_nav/langs/' . $l . '.po' . (($l == 'en') ? 't' : '');
}
if (file_exists($langF)) {
$stat = _po_diff($l, $resource);
$num_of_fuzzy_or_missing = count($stat['fuzzy_or_missing']);
$num_of_untranslated = count($stat['notrans']);
} else { // file $langF doesn't exists
$stat = _po_diff('en', $resource);
$num_of_fuzzy_or_missing = 0;
$num_of_untranslated = count($stat['notrans']);
}
// unify resource names, navigation is a special exception
$resource_name = str_replace(array('../_nav/langs/en', 'en/', '.pot'), array('nav', '', ''), $f);
// create pt_BR from pt-br and alike to unify languages
$web_language_code = locale_hyphen_underscore($l, true);
$num_of_not_fully_trans = $num_of_fuzzy_or_missing + $num_of_untranslated;
$report[] = array(
'num_of_all_strings' => $stat['a'],
'resource_name' => $resource_name,
'web_language_code' => $web_language_code,
'num_of_not_fully_trans' => $num_of_not_fully_trans,
);
}
}
// core part: building the data
$tx_lang_completed_treshold = 90; // report new languages above this treshold from 0 to 100 (%)
$langs_and_res_names_done = FALSE;
$tx_all_languages = array();
$tx_all_langs_above_treshold = array();
$git_all_languages = array();
$tx_all_resource_names = array();
$git_all_resource_names = array();
$git_compare_resources = array();
$tx_git_difference = array();
$nonequal_num_of_all_strings = array();
foreach ($tx_resources_info as $tx_resource_info) {
$tx_resource_name = $tx_resource_info['tx_resource_name'];
if (!in_array($tx_resource_name, $tx_all_resource_names)) {
$tx_all_resource_names[] = $tx_resource_name;
}
foreach ($tx_resource_info['statistic'] as $tx_resource_language => $tx_resource_language_stat) {
$completed = sprintf("%d", $tx_resource_language_stat['completed']);
if (!in_array($tx_resource_language, $tx_all_languages)) {
$tx_all_languages[] = $tx_resource_language;
}
if ($tx_lang_completed_treshold <= $completed) {
if (!in_array($tx_resource_language, $tx_all_langs_above_treshold)) {
$tx_all_langs_above_treshold[] = $tx_resource_language;
}
}
foreach ($report as $git_resource_info) {
$git_resource_name = $git_resource_info['resource_name'];
$git_compare_resource_name = str_replace('/', '-', $git_resource_name);
$git_resource_language = $git_resource_info['web_language_code'];
if (!$langs_and_res_names_done) {
$git_all_languages[] = $git_resource_language;
$git_all_resource_names[] = $git_resource_name;
$git_compare_resources[] = $git_compare_resource_name;
}
// if names and languages match but skip English as a source language
if ($tx_resource_language == $git_resource_language && 'en' != $git_resource_language
&& $tx_resource_name == $git_compare_resource_name) {
$tx_resource_untrans_in_lang = $tx_resource_language_stat['untranslated_entities'];
$tx_resource_all_strings_in_lang = $tx_resource_untrans_in_lang + $tx_resource_language_stat['translated_entities'];
$git_resource_num_of_all_strings = $git_resource_info['num_of_all_strings'];
$git_resource_untrans_in_lang = $git_resource_info['num_of_not_fully_trans'];
// compare l10n level
if ($tx_resource_untrans_in_lang != $git_resource_untrans_in_lang) {
$tx_git_difference[$tx_resource_language][$git_resource_name]['tx_num_of_all_strings'] = $tx_resource_all_strings_in_lang;
$tx_git_difference[$tx_resource_language][$git_resource_name]['tx_untranslated'] = $tx_resource_untrans_in_lang;
$tx_git_difference[$tx_resource_language][$git_resource_name]['git_untranslated'] = $git_resource_untrans_in_lang;
}
// this bellow should normaly only happen inside of a tx sync window so remember it
if ($tx_resource_all_strings_in_lang != $git_resource_num_of_all_strings) {
if (!in_array($git_resource_name, $nonequal_num_of_all_strings)) {
$nonequal_num_of_all_strings[] = $git_resource_name;
}
}
}
}
if (!$langs_and_res_names_done) {
$git_all_languages = array_unique($git_all_languages);
$git_all_resource_names = array_unique($git_all_resource_names);
$git_compare_resources = array_unique($git_compare_resources);
$langs_and_res_names_done = TRUE;
}
}
};
// sorting data
sort($tx_all_resource_names, SORT_STRING);
sort($git_all_resource_names, SORT_STRING);
sort($git_compare_resources, SORT_STRING);
sort($tx_all_languages);
sort($tx_all_langs_above_treshold);
sort($git_all_languages);
sort($nonequal_num_of_all_strings, SORT_STRING);
$tx_only_resources = array_diff($tx_all_resource_names, $git_compare_resources);
$git_only_resources = array_diff($git_compare_resources, $tx_all_resource_names);
$tx_only_languages = array_diff($tx_all_langs_above_treshold, $git_all_languages);
$git_only_languages = array_diff($git_all_languages, $tx_all_languages);
// preparing text for languages not present yet in our git repositories
$tx_only_languages_details = '';
if (0 < count($tx_only_languages)) {
$tx_only_languages_details = "<h3>Languages with at least one resource for $resource_type translated over treshold ";
$tx_only_languages_details .= "($tx_lang_completed_treshold %) but not present yet in our git:</h3>";
$tx_only_languages_details .= '<p>Please add them to our git.</p><ul>';
foreach ($tx_only_languages as $tx_only_language) {
$tx_language_details = tx_call("language/$tx_only_language", '');
$tx_only_languages_details .= '<li><span class="bold">' . $tx_only_language . '</span>: ';
$tx_only_languages_details .= '<a href="http://www.transifex.com/organization/MageiaLinux/dashboard/all_resources/';
$tx_only_languages_details .= "$tx_only_language/#1/?c=$resource_type\">" . $tx_language_details['name'] . "</a>,</li>";
}
$tx_only_languages_details .= '</ul>';
}
// preparing error texts
if (0 < count($git_only_languages)) {
$error = "Some languages (" . implode(", ", $git_only_languages) . ") are present in our git";
$errors['git_only_languages'] .= "$error but they are bellow treshold ($tx_lang_completed_treshold %) in Transifex. Please report that.";
}
if (0 < count($tx_only_resources)) {
$error = "Some resources (" . implode(", ", $tx_only_resources) . ") are present only in Transifex";
$errors['tx_only_resources'] .= "$error but not in our git. Please report that.";
}
if (0 < count($git_only_resources)) {
$error = "Some resources (" . implode(", ", $git_only_resources) . ") are present only in our git";
$errors['git_only_resources'] .= "$error but not in Transifex. Please report that.";
}
if (0 < count($nonequal_num_of_all_strings)) {
$error = "Some resources (" . implode(", ", $nonequal_num_of_all_strings) . ") have different number of all strings";
$errors['nonequal_num_of_all_strings'] .= "$error between our git and Transifex. Please report that on the mailing list if it happens several days.";
}
// making a list of resources with Tx/git differences
ksort($tx_git_difference);
$all_languages_with_tx_git_diff = array();
$all_resources_with_tx_git_diff = array();
foreach ($tx_git_difference as $one_language_of_tx_git_difference => $resources_with_tx_git_difference) {
$all_languages_with_tx_git_diff[] = $one_language_of_tx_git_difference;
foreach ($resources_with_tx_git_difference as $one_resource_with_tx_git_difference => $details) {
$all_resources_with_tx_git_diff[] = $one_resource_with_tx_git_difference;
}
}
$all_resources_with_tx_git_diff = array_unique($all_resources_with_tx_git_diff);
sort($all_resources_with_tx_git_diff, SORT_STRING);
$num_of_resources_w_difference = count($all_resources_with_tx_git_diff);
$table_difference = '';
$num_for_switch_table_to_list = 15;
if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_of_resources_w_difference) {
// preparing a table represantation of Tx/git differences
$i = 0;
$table_rows = array();
$table_rows[] = "<table>" . PHP_EOL;
$table_rows[] = "<thead>" . PHP_EOL;
$first_row_pass = TRUE;
foreach ($tx_git_difference as $one_language => $one_language_array) {
$j = 0;
$row = array();
$first_col_pass = TRUE;
if ($first_row_pass || 0 == $i % 10) {
$array_chunks = array_chunk($all_resources_with_tx_git_diff, $col_repeat = 8, TRUE);
foreach ($array_chunks as $array_chunk) {
$row = array_merge($row, array(' '), $array_chunk);
}
$table_rows[] = "<tr class=\"add\"><th>" . implode("</th><th>", $row) . "</th></tr>" . PHP_EOL; // add header row
$row = array();
}
foreach ($all_resources_with_tx_git_diff as $resource_with_tx_git_diff) {
if ($first_col_pass || 0 == $j % $col_repeat) { // left cell
$row[] = "<div class=\"add\"><span class=\"bold\">" . $langs[locale_underscore_to_hyphen($one_language)] . "</span> - $one_language</div>";
$first_col_pass = FALSE;
}
if (array_key_exists($resource_with_tx_git_diff, $one_language_array)) {
$stat_data = array();
$stat_data['tx_untran'] = $one_language_array[$resource_with_tx_git_diff]['tx_untranslated'];
$stat_data['git_untran'] = $one_language_array[$resource_with_tx_git_diff]['git_untranslated'];
$cell = "<span class=\"stat\">";
$cell .= build_links($resource_with_tx_git_diff, $one_language, $resource_type, $stat_data);
$cell .= "</span>";
$row[] = $cell;
} else {
$row[] = ' '; // there is no differences
}
$j++;
}
$table_rows[] = "<tr><td class=\"add\">" . implode("</td><td>", $row) . "</td></tr>" . PHP_EOL;
if ($first_row_pass) {
$table_rows[] = "</thead>" . PHP_EOL;
$table_rows[] = "<tbody>" . PHP_EOL;
$first_row_pass = FALSE;
}
$i++;
}
$table_rows[] = "</tbody>" . PHP_EOL;
$table_rows[] = "</table>" . PHP_EOL;
$table_difference = implode($table_rows);
}
$list_of_lang_diff = '';
$list_of_resource_diff = '';
if (0 < $num_of_resources_w_difference) {
// preparing a list represantation of Tx/git differences by language
$list_of_lang_diff .= '<ul>' . PHP_EOL;
foreach ($tx_git_difference as $one_language => $one_language_array) {
$list_of_lang_diff .= '<li><span class="bold">' . $langs[locale_underscore_to_hyphen($one_language)];
$list_of_lang_diff .= '</span> - ' . $one_language . ': ' . PHP_EOL;
$one_language_resources = array_keys($one_language_array);
$miss_first = TRUE;
foreach ($one_language_resources as $one_language_resource) {
$stat_data = array();
$stat_data['tx_untran'] = $one_language_array[$one_language_resource]['tx_untranslated'];
$stat_data['git_untran'] = $one_language_array[$one_language_resource]['git_untranslated'];
$list_of_lang_diff .= ($miss_first ? '' :', ');
$list_of_lang_diff .= "<span class=\"italic\">$one_language_resource</span> <span class=\"stat\">(";
$list_of_lang_diff .= build_links($one_language_resource, $one_language, $resource_type, $stat_data);
$list_of_lang_diff .= ')</span>';
$miss_first = FALSE;
}
$list_of_lang_diff .= '</li>' . PHP_EOL;
}
$list_of_lang_diff .= '</ul>' . PHP_EOL;
// preparing a list represantation of Tx/git differences by resources
$list_of_resource_diff .= '<ul>' . PHP_EOL;
foreach ($all_resources_with_tx_git_diff as $resource_with_tx_git_diff) {
$list_of_resource_diff .= '<li><span class="bold">' . $resource_with_tx_git_diff .'</span>: ' . PHP_EOL;
$miss_first = TRUE;
foreach ($tx_git_difference as $one_language => $one_language_array) {
if (isset($one_language_array[$resource_with_tx_git_diff])) {
$stat_data = array();
$stat_data['tx_untran'] = $one_language_array[$resource_with_tx_git_diff]['tx_untranslated'];
$stat_data['git_untran'] = $one_language_array[$resource_with_tx_git_diff]['git_untranslated'];
$list_of_resource_diff .= ($miss_first ? '' :', ');
$list_of_resource_diff .= '<span class="italic">' . $langs[locale_underscore_to_hyphen($one_language)];
$list_of_resource_diff .= "</span> - $one_language <span class=\"stat\">(";
$list_of_resource_diff .= build_links($resource_with_tx_git_diff, $one_language, $resource_type, $stat_data);
$list_of_resource_diff .= ')</span>';
$miss_first = FALSE;
}
}
$list_of_resource_diff .= '</li>' . PHP_EOL;
}
$list_of_resource_diff .= '</ul>' . PHP_EOL;
}
// print out any errors
if (0 < count($errors)) {
$error_text = '<ul>';
foreach ($errors as $single_error) {
$error_text .= '<li class="bold">' . $single_error . '</li>';
}
$error_text .= '</ul>';
echo $error_text . PHP_EOL;
}
// print any languages present only in Transifex
echo $tx_only_languages_details . PHP_EOL;
// print any differences between Transifex and our git repository
echo '<h3>Languages bellow have some differences between Transifex and our git repository.</h3>';
echo '<p>To avoid furter alienation and confusion please synchronise them.</p>';
echo '<p>They differs on number of untranslated strings in resources:</p>';
if (0 < $num_of_resources_w_difference) {
// print table if there are only a few resources with differences otherwise print a list
if ($num_for_switch_table_to_list > $num_of_resources_w_difference) {
echo $table_difference . PHP_EOL;
} else {
echo $list_of_lang_diff . PHP_EOL;
echo '<h3>Same list but arranged by resources:</h3>';
echo $list_of_resource_diff . PHP_EOL;
}
}
?>
<p>Source code for this website is
<a href="http://gitweb.mageia.org/web/www/tree/langs/report_tx_git.php">available on git</a>.</p>
</div>
<?php echo '<script src="/_nav/js/source.js"></script>' ?>
</body>
</html>
|