aboutsummaryrefslogtreecommitdiffstats
path: root/langs/report_tx_git.php
blob: d6f108b1587764b3a1f27bd44f4e95651e1249e1 (plain)
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<!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>Languages translation progress report for web pages is available <a href="./report.php">here</a>.</p>

<?php
define('HLANG', TRUE);
include 'lib.php';

$errors = array(); // stored for error management ;)
$wanted_category = get_sane_string('c');
if (in_array($wanted_category, array('Webpages', 'Documentation', 'Cauldron'))) {
    $resource_type = $wanted_category; // filter only valid resource types
} else {
    $resource_type = 'Webpages'; // default
}
$wanted_language   = get_sane_string('l');
$wanted_lang_name  = '';
if (!empty($wanted_language)) {
    $wanted_lang_name  = get_language_name($wanted_language) . " (";
    $wanted_lang_name .= build_transifex_link($wanted_language, NULL, $resource_type) . ")";
}
// NOTE: there is a different naming convention between Tx and git for some lanuages:
//      Tx              git
//      sr@latin    vs. sr@Latn.po
//      sr@latin    vs. sr@latin.po     exception: http://gitweb.mageia.org/software/i18n/system-config-printer/plain/po
//      uz@Cyrl     vs. uz@cyrillic.po
//      en_GB       vs. en_gb.po        exception: http://gitweb.mageia.org/web/identity/plain/lib/CatDap/I18N
$wanted_resource = get_sane_string('r');
$wanted_resource_name = '';
if (!empty($wanted_resource)) {
    $wanted_resource_name = str_replace(array('../_nav/langs/en', 'en/', '.pot'), array('nav', '', ''), $wanted_resource);
}

include 'resources_list.php';

// get resources data from TX
$tx_resources = tx_call("resources");

$details_wanted = FALSE;
if (!empty($wanted_language) && !empty($wanted_resource_name)) {
    $details_wanted = TRUE;
}

$parsed_tx_file_content = NULL;
if ($details_wanted) {
    $prefixed_resource_name = resource_name_conversion($wanted_resource_name, $wanted_category);
    $tx_file = tx_call("resource/$prefixed_resource_name/translation/$wanted_language/");
    if (!empty($tx_file)) {
        $tx_file_content = $tx_file['content'];
        $tx_file_content = explode("\n", $tx_file_content);
        if ('mageiasync' == $wanted_resource_name) { // treat TS files differently
            $parsed_tx_file_content = _parse_ts_file($tx_file_content, FALSE);
        } else {
            $parsed_tx_file_content = phpmo_parse_po_file($tx_file_content, FALSE);
        }
    }
}

// create separate array ($tx_resources_info) and add statistics to it from TX
$tx_resources_info     = array();
$tx_cauldron_resources = array();
$tx_stat_for_resource  = array();
foreach ($tx_resources as $one_resource) {
    $tx_resource_name = $one_resource['slug'];
    $category         = $one_resource['categories'][0];
    $add_data         = FALSE;
    if ('Cauldron' == $category) {
        $tx_cauldron_resources[] = $tx_resource_name;
    }
    // limit resource type to one
    if ($category == $resource_type) {
        if ('Cauldron' == $category) { // add data for Cauldron category
            // if name is required
            if (!empty($wanted_resource) && $tx_resource_name == resource_name_conversion($wanted_resource_name, $category)) {
                $add_data = TRUE;
            // if only language is required
            } else if (!empty($wanted_language) && empty($wanted_resource)) {
                $add_data = TRUE;
            }
        } else { // add data for Webpages and Documentation category
            if (empty($wanted_resource) && empty($wanted_language)) {
                $add_data = TRUE;
            }
        }
        // add data if details are needed
        if ($details_wanted && $tx_resource_name == resource_name_conversion($wanted_resource_name, $category)) {
            $add_data = TRUE;
        }
    }
    if ($add_data) {
        // add statistic
        if (empty($wanted_language)) {
            $tx_stat_for_resource = tx_call("resource/$tx_resource_name/stats");
        } else {
            $tx_stat_for_resource[$wanted_language] = tx_call("resource/$tx_resource_name/stats/$wanted_language");
        }
        $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[$tx_resource_name] = $one_resource;
    }
}
$tx_languages = array();
if (empty($wanted_language)) {
    if ('Webpages' == $resource_type || 'Documentation' == $resource_type) {
        $tx_stat_for_resource = tx_call("resource/page-index/stats");
        $tx_languages = array_keys($tx_stat_for_resource);
    } else {
        foreach ($tx_stat_for_resource as $tx_resource_language => $tx_resource_language_stat) {
            $tx_languages[] = $tx_resource_language;
        }
    }
} else {
    $tx_stat_for_resource = tx_call("resource/$tx_resource_name/stats");
    $tx_languages = array_keys($tx_stat_for_resource);
}

// create array ($report) with statistics from git
$report = array();
if ('Webpages' == $resource_type) {
    if (empty($wanted_resource) && empty($wanted_language)) {
        $enFiles = array_merge(array('../_nav/langs/en.pot'), get_lang_references('*.pot')); // added navigation file
        $report = generating_report(get_other_langs(), $enFiles);
    } else {
        $enFiles = array($wanted_resource);
        $report = generating_report(array($wanted_language), $enFiles, NULL, NULL, $parsed_tx_file_content);
    }
} else {
    $tx_resources_not_yet_in_git = array();
    $translated_in_tx = ' translated in Transifex';
    foreach ($git_resources as $git_resource_details) {
        $tx_name  = $git_resource_details['tx_name'];
        if (!empty($wanted_resource) && $tx_name != $wanted_resource) {
            continue;
        }
        $git_path = $git_resource_details['git_path'];
        $pot_name = $git_resource_details['pot_name'];
        $raw_html_dump = file_get_contents($git_path);
        if (FALSE === $raw_html_dump) {
            $errors['file_get_contents_failed'] = "Access to $git_path failed.";
        }
        // list all po files from links within $raw_html_dump
        if (false !== strpos($pot_name, '_en.ts')) { // treat TS files differently
            $first_part_pot_name = substr($pot_name, 0, -5); // cuts 'en.ts' from mageiaSync_en.ts
            preg_match_all("/('>$first_part_pot_name)([a-z_A-Z0-9@-]+)(\.ts<)/", $raw_html_dump, $language_codes);
        } else {
            preg_match_all("/('>)([a-z_A-Z0-9@-]+)(\.po<)/", $raw_html_dump, $language_codes);
        }
        $git_language_codes = $language_codes[2];
        if (empty($wanted_language)) {
            $report_language_codes = $git_language_codes;
        } else {
            if (in_array($wanted_language, $git_language_codes)) {
                $report_language_codes = array($wanted_language);
            } else {
                $report_language_codes = array();
                $completion  = $tx_resources_info[$tx_name]['statistic'][$wanted_language]['completed'];
                $completion .= $translated_in_tx;
                $translated_in_tx = '';
                $tx_resources_not_yet_in_git[] = "$tx_name ($completion)";
                $resources_not_yet_in_git = implode(", ", $tx_resources_not_yet_in_git);
                $errors['lang_not_in_git'] = "Language $wanted_lang_name is not present in git for $resources_not_yet_in_git resource.";
            }
        }
        $one_report = generating_report(array_values($report_language_codes), array($tx_name), $git_path, $pot_name, $parsed_tx_file_content);
        $report = array_merge($one_report, $report);
    }
}

// core part: building the data
$tx_lang_completed_treshold  = 75; // 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();
$parse_errors                = 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) {
        if (array_key_exists('completed', $tx_resource_language_stat)) {
            $completed = sprintf("%d", $tx_resource_language_stat['completed']);
        } else {
            $completed = 0;
        }
        if (!in_array($tx_resource_language, $tx_all_languages)) {
            $tx_all_languages[] = $tx_resource_language;
        }
        if ($tx_lang_completed_treshold <= $completed && 'en' != $tx_resource_language) {
            $tx_all_langs_above_treshold[$tx_resource_language][] = $tx_resource_name;
        }
        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) {

                if (array_key_exists('untranslated_entities', $tx_resource_language_stat)) {
                    $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'];
                } else {
                    $tx_resource_untrans_in_lang     = 0;
                    $tx_resource_all_strings_in_lang = 0;
                }

                $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'];
                $git_resource_path               = $git_resource_info['webgit_path'];
                $git_resource_pot_name           = $git_resource_info['pot_name'];
                $git_resource_differences        = $git_resource_info['differences'];

                // compare l10n level or differences
                if ($tx_resource_untrans_in_lang != $git_resource_untrans_in_lang || count($git_resource_differences) != 0) {
                    $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;
                    $tx_git_difference[$tx_resource_language][$git_resource_name]['webgit_path']           = $git_resource_path;
                    $tx_git_difference[$tx_resource_language][$git_resource_name]['pot_name']              = $git_resource_pot_name;
                    $tx_git_difference[$tx_resource_language][$git_resource_name]['differences']           = $git_resource_differences;
                }
                // it seems like a parse error
                if (0 == $git_resource_num_of_all_strings) {
                    $parse_errors[$git_resource_name][] = $git_resource_language;
                // this below should normaly only happen inside of a tx sync window so remember it
                } else if ($tx_resource_all_strings_in_lang != $git_resource_num_of_all_strings) {
                    if (!array_key_exists($git_resource_name, $nonequal_num_of_all_strings)) {
                        $nonequal_num_text = "$git_resource_name git:$git_resource_num_of_all_strings/tx:$tx_resource_all_strings_in_lang";
                        $nonequal_num_of_all_strings[$git_resource_name] = $nonequal_num_text;
                    }
                }
            }
        }
        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);
ksort($tx_all_langs_above_treshold); // sort by lang
sort($git_all_languages);
sort($nonequal_num_of_all_strings, SORT_STRING);

$tx_all_resources_above_treshold = array();
foreach ($tx_all_langs_above_treshold as $tx_only_language => $resource_above_treshold_for_lang) {
    foreach ($resource_above_treshold_for_lang as $resource_above_treshold) {
        $tx_all_resources_above_treshold[] = $resource_above_treshold;
    }
}
$tx_all_resources_above_treshold = array_unique($tx_all_resources_above_treshold);
sort($tx_all_resources_above_treshold, SORT_STRING);

$tx_only_resources  = array_diff($tx_all_resources_above_treshold, $git_compare_resources);
$git_only_resources = array_diff($git_compare_resources, $tx_all_resource_names);
$tx_only_languages  = array_diff(array_keys($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)) {
    if (!empty($wanted_language) && !empty($wanted_resource)) {
        $tx_only_languages_details = "<h3>Language $wanted_lang_name with $wanted_resource resource for $resource_type translated over treshold ";
    } else if (!empty($wanted_language) && empty($wanted_resource)) {
        $tx_only_languages_details = "<h3>Language $wanted_lang_name with at least one resource for $resource_type translated over treshold ";
    } else if (empty($wanted_language) && !empty($wanted_resource)) {
        $tx_only_languages_details = "<h3>Languages with $wanted_resource resource for $resource_type translated over treshold ";
    } else {
        $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 %) in Transifex but not present yet in our git:</h3><ul>";
    foreach ($tx_only_languages as $tx_only_language) {
        $language_name = get_language_name($tx_only_language);
        $tx_only_languages_details .= '<li><span class="bold">' . $language_name . '</span>: ';
        if (empty($wanted_resource)) {
            $tx_only_languages_details .= build_transifex_link($tx_only_language, NULL, $resource_type);
            $tx_only_languages_details .= " (resources over treshold: ";
            $resources_above_treshold = array();
            foreach ($tx_all_langs_above_treshold[$tx_only_language] as $resource_above_treshold) {
                $level = $tx_resources_info[$resource_above_treshold]['statistic'][$tx_only_language]['completed'];
                $resources_above_treshold[] = "$resource_above_treshold at $level";
            }
            sort($resources_above_treshold, SORT_STRING);
            $tx_only_languages_details .= implode(", ", $resources_above_treshold) . ")";
        } else {
            $tx_only_languages_details .= build_transifex_link($tx_only_language, $tx_only_language, $resource_type, $wanted_resource);
            $level = $tx_resources_info[$wanted_resource]['statistic'][$tx_only_language]['completed'];
            $tx_only_languages_details .= " ($level translated)";
        }
        $tx_only_languages_details .= ",</li>";
    }
    $tx_only_languages_details .= '</ul>';
}

// preparing error texts
if (0 < count($git_only_languages)) {
    $error                        = "Note that some languages (" . implode(", ", $git_only_languages) . ") are present in our git";
    $errors['git_only_languages'] = "$error but they are below treshold ($tx_lang_completed_treshold %) in Transifex.";
}

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($parse_errors)) {
    $errors_in_parsing            = array();
    foreach ($parse_errors as $single_git_resource_name => $git_resource_languages) {
        $errors_in_parsing[]      = "$single_git_resource_name.po (languages: " . implode(", ", $git_resource_languages) . ")";
    }
    $reload                       = "Please reload the page later and report this on mailing list if it persist.";
    $errors['po_file_parse']      = "It seems that parsing of some resources failed: " . implode(", ", $errors_in_parsing) . ". $reload";
}

if (0 < count($nonequal_num_of_all_strings)) {
    $error                                 = "Some resources (" . implode(", ", $nonequal_num_of_all_strings) . ") ";
    $error                                .= "have different number of all strings between our git and Transifex.";
    $errors['nonequal_num_of_all_strings'] = "$error Please report that on the mailing list if it happens across several days.";
}

// making a list of resources with Tx/git differences
ksort($tx_git_difference);
$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);

// preparing a detailed strings difference html table represantation between git and tx
if ($details_wanted) {
    $table_rows   = array();
    $table_rows[] = "<table>" . PHP_EOL;
    $table_rows[] = "<thead>" . PHP_EOL;
    $table_rows[] = "<tr class=\"add\"><th>Original string</th><th>Translated string from git</th><th>And translated string from Transifex</th></tr>" . PHP_EOL; // add header row
    $table_rows[] = "</thead>" . PHP_EOL;
    $table_rows[] = "<tbody>" . PHP_EOL;
    $num_of_differences = 0;
    $col_repeat = 8;
    $i = 0;
    foreach ($tx_git_difference as $one_language => $one_language_array) {
        $differences = $one_language_array[$wanted_resource_name]['differences'];
        $num_of_differences = count($differences);
        foreach ($differences as $curr_msgid => $curr_context_array) {
            foreach ($curr_context_array as $curr_context_or_num => $array_for_compare) {
                if (is_string($curr_context_or_num)) {
                    $curr_msgid .= " (Context: $curr_context_or_num)";
                }
                $curr_msgid = htmlentities($curr_msgid, null, 'UTF-8');
                $num_of_tr_str = max(count($array_for_compare['target_l']), count($array_for_compare['compared'])) - 1;
                for ($i = 0; $i <= $num_of_tr_str; $i++) {
                    if (empty($array_for_compare['target_l'][$i])) {
                        $target_l_str = '&nbsp;';
                    } else {
                        $target_l_str = htmlentities($array_for_compare['target_l'][$i], null, 'UTF-8');
                    }
                    if (empty($array_for_compare['compared'][$i])) {
                        $compared_str = '&nbsp;';
                    } else {
                        $compared_str = htmlentities($array_for_compare['compared'][$i], null, 'UTF-8');
                    }
                    $row  = "<tr><td class=\"add\">$curr_msgid</td>";
                    $row .= "<td>$target_l_str</td>";
                    $row .= "<td>$compared_str</td></tr>";
                    $table_rows[] = $row . PHP_EOL;
                    // instead of msgid use msgid_plural for plural table lines
                    if (is_array($array_for_compare['target_l'])) {
                        if (array_key_exists('msgid_plural', $array_for_compare['target_l'])) {
                            $curr_msgid = str_replace($curr_msgid, $array_for_compare['target_l']['msgid_plural'], $curr_msgid);
                        }
                    }
                }
            }
        }
    }
    $table_rows[] = "</tbody>" . PHP_EOL;
    $table_rows[] = "</table>" . PHP_EOL;

    if (0 != $num_of_differences) {
        $table_w_details = implode($table_rows);
    } else {
        $table_w_details = '';
        $all_resources_with_tx_git_diff = array();
    }
}

$num_of_resources_w_difference = count($all_resources_with_tx_git_diff);

// preparing a html table represantation of git/tx difference in number of untranslated strings
$table_difference = '';
$num_for_switch_table_to_list = 15;
$table_num_diff = FALSE;
if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_of_resources_w_difference) {
    $table_num_diff = TRUE;
    // 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;
    $col_repeat = 8;
    foreach ($tx_git_difference as $one_language => $one_language_array) {
        $j   = 0;
        $row = array();
        $first_col_pass = TRUE;
        if ($first_row_pass || 0 == $i % 12) {
            $array_chunks = array_chunk($all_resources_with_tx_git_diff, $col_repeat, TRUE);
            foreach ($array_chunks as $array_chunk) {
                $row = array_merge($row, array('&nbsp;'), $array_chunk);
            }
            $table_rows[] = "<tr class=\"add\"><th>" . implode("</th><th>", $row) . "</th></tr>" . PHP_EOL; // add header row
            if ($first_row_pass) {
                $table_rows[] = "</thead>" . PHP_EOL;
                $table_rows[] = "<tbody>" . PHP_EOL;
                $first_row_pass = FALSE;
            }
        }

        $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
                    $language_name = get_language_name($one_language);
                    $row[] = "<div class=\"add\"><span class=\"bold\">$language_name</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['num_of_all'] = $one_language_array[$resource_with_tx_git_diff]['tx_num_of_all_strings'];
                    $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'];
                    $stat_data['git_path']   = $one_language_array[$resource_with_tx_git_diff]['webgit_path'];
                    $stat_data['pot_name']   = $one_language_array[$resource_with_tx_git_diff]['pot_name'];

                    $cell  = "<span class=\"stat\">";
                    $cell .= build_links($resource_with_tx_git_diff, $one_language, $resource_type, $stat_data);
                    $cell .= "</span>";
                    $row[] = $cell;
                } else {
                    $row[] = '&nbsp;'; // there is no differences
                }
                $j++;
        }
        $table_rows[] = "<tr><td class=\"add\">" . implode("</td><td>", $row) . "</td></tr>" . PHP_EOL;
        $i++;
    }
    $table_rows[] = "</tbody>" . PHP_EOL;
    $table_rows[] = "</table>" . PHP_EOL;
    $table_difference = implode($table_rows);
}

// preparing a html list represantation of git/tx difference in number of untranslated strings, one by language other by resources
$list_of_lang_diff     = '';
$list_of_resource_diff = '';
$list_num_diff = FALSE;
if (0 < $num_of_resources_w_difference && !$details_wanted && !$table_num_diff) {
    $list_num_diff = TRUE;
    // 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) {
        $language_name = get_language_name($one_language);
        $list_of_lang_diff .= "<li><span class=\"bold\">$language_name</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['num_of_all'] = $one_language_array[$one_language_resource]['tx_num_of_all_strings'];
            $stat_data['tx_untran']  = $one_language_array[$one_language_resource]['tx_untranslated'];
            $stat_data['git_untran'] = $one_language_array[$one_language_resource]['git_untranslated'];
            $stat_data['git_path']   = $one_language_array[$one_language_resource]['webgit_path'];
            $stat_data['pot_name']   = $one_language_array[$one_language_resource]['pot_name'];

            $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['num_of_all'] = $one_language_array[$resource_with_tx_git_diff]['tx_num_of_all_strings'];
                $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'];
                $stat_data['git_path']   = $one_language_array[$resource_with_tx_git_diff]['webgit_path'];
                $stat_data['pot_name']   = $one_language_array[$resource_with_tx_git_diff]['pot_name'];

                $list_of_resource_diff .= ($miss_first ? '' :', ');
                $language_name = get_language_name($one_language);
                $list_of_resource_diff .= "<span class=\"italic\">$language_name</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 links for diferent reports
if ('Webpages' != $resource_type) {
    $links[] = '<a href="./report_tx_git.php?c=Webpages">website translations</a>';
}
if ('Documentation' != $resource_type) {
    $links[] = '<a href="./report_tx_git.php?c=Documentation">documentation translations</a>';
}
if ('Cauldron' != $resource_type) {
//    $links[] = '<a href="./report_tx_git.php?c=Cauldron">software translations</a>';
}

// list $tx_languages and $tx_cauldron_resources
$languages_links = array();
foreach ($tx_languages as $tx_language) {
    $language_name = get_language_name($tx_language);
    $languages_links[] = "<a href=\"./report_tx_git.php?c=Cauldron&amp;l=$tx_language\" title=\"$language_name\">$tx_language</a>";
}
sort($languages_links, SORT_STRING);
$num_of_tx_langs = count($languages_links);
$languages_link  = implode(", ", $languages_links);
$resources_links = array();
foreach ($tx_cauldron_resources as $tx_resource_name) {
    $resources_links[] = "<a href=\"./report_tx_git.php?c=Cauldron&amp;r=$tx_resource_name\">$tx_resource_name</a>";
}
$num_of_tx_cauldron_resources = count($resources_links);
$resources_link = implode(", ", $resources_links);

$reports_links  = '<p>You can also see reports about differences in ' . implode(" or ", $links) . '.</p>';
$reports_links .= "<p>For software translations please choose one of it's $num_of_tx_cauldron_resources resources ($resources_link) or one of a $num_of_tx_langs languages ($languages_link).</p>";
$reports_links .= '<p>There is a nice ';
$reports_links .= '<a href="https://wiki.mageia.org/en/Transifex_and_git_syncing">wiki page about Transifex and git synchronising</a>.</p>';
echo $reports_links . PHP_EOL;

// print out any errors
if (0 < count($errors)) {
    $error_text  = '<h3>There seems to be some errors during processing this time :(</h3>';
    $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;

$diff_desc = "between Transifex and our git repository for $resource_type.";
if (0 < $num_of_resources_w_difference) {
    // print any differences between Transifex and our git repository
    if (!empty($wanted_resource) && !empty($wanted_language)) {
        $diff_title = "<h3>Language $wanted_lang_name below have some differences in resource $wanted_resource $diff_desc</h3>";
    } else if (!empty($wanted_resource) && empty($wanted_language)) {
        $diff_title = "<h3>Languages below have some differences in resource $wanted_resource $diff_desc</h3>";
    } else if (empty($wanted_resource) && !empty($wanted_language)) {
        $diff_title = "<h3>Language $wanted_lang_name below have some differences $diff_desc</h3>";
    } else {
        $diff_title = "<h3>Languages below have some differences in resources $diff_desc</h3>";
    }
    echo $diff_title;
    echo '<p>To avoid further alienation and confusion please synchronise them.</p>';
    echo '<p>They differs on number of untranslated strings in resources:</p>';
    // print a detailed strings difference table if wanted
    if ($details_wanted) {
        echo $table_w_details . PHP_EOL;
    // else print table if there are only a few resources with differences otherwise print a list
    } else if ($table_num_diff) {
        echo $table_difference . PHP_EOL;
    } else if ($list_num_diff) {
        echo $list_of_lang_diff . PHP_EOL;
        echo '<h3>Same list but arranged by resources:</h3>';
        echo $list_of_resource_diff . PHP_EOL;
    }
} else if (0 == count($tx_only_languages) && !array_key_exists('tx_call', $errors)) {
    if (!empty($wanted_resource) && !empty($wanted_language)) {
        $diff_title = "<h3>Congratulations. It seems that resource $wanted_resource in language $wanted_lang_name have no differences $diff_desc</h3>";
    } else if (!empty($wanted_resource) && empty($wanted_language)) {
        $diff_title = "<h3>Congratulations. It seems that resource $wanted_resource has no differences $diff_desc</h3>";
    } else if (empty($wanted_resource) && !empty($wanted_language)) {
        $diff_title = "<h3>Congratulations. It seems that in language $wanted_lang_name there is no resources with differences $diff_desc</h3>";
    } else {
        $diff_title = "<h3>Congratulations. It seems that there is no resources with differences $diff_desc</h3>";
    }
    echo $diff_title;
}
?>
    <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>