aboutsummaryrefslogtreecommitdiffstats
path: root/langs/report_tx_git.php
diff options
context:
space:
mode:
Diffstat (limited to 'langs/report_tx_git.php')
-rw-r--r--langs/report_tx_git.php118
1 files changed, 87 insertions, 31 deletions
diff --git a/langs/report_tx_git.php b/langs/report_tx_git.php
index 30b8ecefb..5328d16a7 100644
--- a/langs/report_tx_git.php
+++ b/langs/report_tx_git.php
@@ -3,7 +3,7 @@
<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>
+ <title>www.mageia.org report about differences between Transifex and git repositories</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 {
@@ -22,7 +22,7 @@
</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>
+ <h1><a href="//www.mageia.org/">www.mageia.org</a> report about differences between Transifex and git repositories</h1>
<ul>
<li> </li>
</ul>
@@ -32,6 +32,9 @@
<p>Languages translation progress report for web pages is available <a href="./report.php">here</a>.</p>
<?php
+// TODO:
+// fix one lang or one resource in $wanted_category: Webpages
+
define('HLANG', TRUE);
include 'lib.php';
@@ -65,6 +68,7 @@ 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;
@@ -87,20 +91,21 @@ if ($details_wanted) {
// create separate array ($tx_resources_info) and add statistics to it from TX
$tx_resources_info = array();
+$tx_resources_list = 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];
+ $categories = explode(" ", $one_resource['categories'][0]);
$add_data = FALSE;
- if ('Cauldron' == $category) {
+ if (in_array('Cauldron', $categories)) {
$tx_cauldron_resources[] = $tx_resource_name;
}
// limit resource type to one
- if ($category == $resource_type) {
- if ('Cauldron' == $category) { // add data for Cauldron category
+ if (in_array($resource_type, $categories)) {
+ if (in_array('Cauldron', $categories)) { // add data for Cauldron category
// if name is required
- if (!empty($wanted_resource) && $tx_resource_name == resource_name_conversion($wanted_resource_name, $category)) {
+ if (!empty($wanted_resource) && $tx_resource_name == resource_name_conversion($wanted_resource_name, $wanted_category)) {
$add_data = TRUE;
// if only language is required
} else if (!empty($wanted_language) && empty($wanted_resource)) {
@@ -112,9 +117,10 @@ foreach ($tx_resources as $one_resource) {
}
}
// add data if details are needed
- if ($details_wanted && $tx_resource_name == resource_name_conversion($wanted_resource_name, $category)) {
+ if ($details_wanted && $tx_resource_name == resource_name_conversion($wanted_resource_name, $wanted_category)) {
$add_data = TRUE;
}
+ $tx_resources_list[] = $tx_resource_name;
}
if ($add_data) {
// add statistic
@@ -146,14 +152,22 @@ if (empty($wanted_language)) {
// create array ($report) with statistics from git
$report = array();
+$git_resources_list = 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 {
+ } else if (!empty($wanted_resource)) {
$enFiles = array($wanted_resource);
+ $report = generating_report(get_other_langs(), $enFiles);
+ } else if (!empty($wanted_language)) { // TODO
+ $enFiles = array_merge(array('../_nav/langs/en.pot'), get_lang_references('*.pot'));
$report = generating_report(array($wanted_language), $enFiles, NULL, NULL, $parsed_tx_file_content);
}
+ foreach ($enFiles as $git_resource_webpage_name) {
+ $git_webpage_name = resource_name_conversion($git_resource_webpage_name, $wanted_category, TRUE); // TRUE
+ $git_resources_list[] = $git_webpage_name;
+ }
} else {
$tx_resources_not_yet_in_git = array();
$translated_in_tx = ' translated in Transifex';
@@ -164,18 +178,26 @@ if ('Webpages' == $resource_type) {
}
$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);
+ if (isset($git_resource_details['github_path'])) { // treat resources on GitHub differently
+ $github_raw_path = $git_resource_details['github_path'];
+ $github_raw_html_dump = file_get_contents($github_raw_path);
+ preg_match_all('/\"(\w*)\.po\"/m', $github_raw_html_dump, $language_codes);
+ $git_language_codes = $language_codes[1];
} else {
- preg_match_all("/('>)([a-z_A-Z0-9@-]+)(\.po<)/", $raw_html_dump, $language_codes);
+ $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[1];
}
- $git_language_codes = $language_codes[2];
+
if (empty($wanted_language)) {
$report_language_codes = $git_language_codes;
} else {
@@ -193,11 +215,12 @@ if ('Webpages' == $resource_type) {
}
$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);
+ $git_resources_list[] = $tx_name;
}
}
// core part: building the data
-$tx_lang_completed_treshold = 75; // report new languages above this treshold from 0 to 100 (%)
+$tx_lang_completed_treshold = 10; // 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();
@@ -304,8 +327,10 @@ $tx_only_resources = array_diff($tx_all_resources_above_treshold, $git_compare_
$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);
+$new_resources_in_tx = array_diff($git_resources_list, $tx_resources_list);
+$new_resources_in_git = array_diff($tx_resources_list, $git_resources_list);
-// preparing text for languages not present yet in our git repositories
+// preparing text for languages not present yet in git repositories
$tx_only_languages_details = '';
if (0 < count($tx_only_languages)) {
if (!empty($wanted_language) && !empty($wanted_resource)) {
@@ -317,7 +342,7 @@ if (0 < count($tx_only_languages)) {
} 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>";
+ $tx_only_languages_details .= "($tx_lang_completed_treshold %) in Transifex but not present yet in 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>: ';
@@ -343,12 +368,21 @@ if (0 < count($tx_only_languages)) {
// preparing error texts
if (0 < count($git_only_languages)) {
- $error = "Note that some languages (" . implode(", ", $git_only_languages) . ") are present in our git";
+ $error = "Note that some languages (" . implode(", ", $git_only_languages) . ") are present in git";
$errors['git_only_languages'] = "$error but they are below treshold ($tx_lang_completed_treshold %) in Transifex.";
}
+if (0 < count($new_resources_in_tx) && (empty($wanted_resource))) {
+ $error = "Some resources (" . implode(", ", $new_resources_in_tx) . ") are new in Transifex";
+ $errors['new_resources_in_tx'] = "$error but not present in resources_list.php file so not processed. Please report that.";
+}
+
+if (0 < count($new_resources_in_git) && (empty($wanted_resource))) {
+ $error = "Some resources (" . implode(", ", $new_resources_in_git) . ") are new in git";
+ $errors['new_resources_in_git'] = "$error but not present in Transifex so not processed. Please report that.";
+}
if (0 < count($git_only_resources)) {
- $error = "Some resources (" . implode(", ", $git_only_resources) . ") are present only in our git";
+ $error = "Some resources (" . implode(", ", $git_only_resources) . ") are present only in git";
$errors['git_only_resources'] = "$error but not in Transifex. Please report that.";
}
@@ -363,7 +397,7 @@ if (0 < count($parse_errors)) {
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.";
+ $error .= "have different number of all strings between git and Transifex.";
$errors['nonequal_num_of_all_strings'] = "$error Please report that on the mailing list if it happens across several days.";
}
@@ -451,6 +485,12 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o
$table_rows[] = "<thead>" . PHP_EOL;
$first_row_pass = TRUE;
$col_repeat = 8;
+ $limit_factor_difference = 10; // difference is bigger than 10%
+ $limit_number_difference = 50; // difference is bigger than 50 strings
+ $clr_red = ' style="background-color: hsl(0, 100%, 85%);"';
+ $clr_yellow = ' style="background-color: hsl(60, 100%, 85%);"';
+ $legend = '';
+ $show_legend = FALSE;
foreach ($tx_git_difference as $one_language => $one_language_array) {
$j = 0;
$row = array();
@@ -483,7 +523,18 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o
$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\">";
+ $completion_difference_number = abs($stat_data['tx_untran'] - $stat_data['git_untran']);
+ $completion_difference_factor = $completion_difference_number / $stat_data['num_of_all'];
+ if (0 == $stat_data['tx_untran'] || 0 == $stat_data['git_untran']) {
+ $cell_style = $clr_red;
+ $show_legend = TRUE;
+ } else if ($limit_factor_difference < 100 * $completion_difference_factor || $limit_number_difference < $completion_difference_number) { // difference is bigger than limits
+ $cell_style = $clr_yellow;
+ $show_legend = TRUE;
+ } else {
+ $cell_style = '';
+ }
+ $cell = "<span$cell_style class=\"stat\">";
$cell .= build_links($resource_with_tx_git_diff, $one_language, $resource_type, $stat_data);
$cell .= "</span>";
$row[] = $cell;
@@ -495,6 +546,10 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o
$table_rows[] = "<tr><td class=\"add\">" . implode("</td><td>", $row) . "</td></tr>" . PHP_EOL;
$i++;
}
+ if (TRUE == $show_legend) {
+ $legend = " (<span$clr_yellow>difference is bigger than $limit_factor_difference% or ";
+ $legend .= "$limit_number_difference strings</span>, <span$clr_red>fully translated in either git or Transifex</span>)";
+ }
$table_rows[] = "</tbody>" . PHP_EOL;
$table_rows[] = "</table>" . PHP_EOL;
$table_difference = implode($table_rows);
@@ -587,14 +642,15 @@ $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>For software translations please choose one of it's $num_of_tx_cauldron_resources resources ($resources_link) or ";
+$reports_links .= "one of a $num_of_tx_langs languages with variants ($languages_link) currently present in Transifex.</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 = '<h3>There seems to be some errors, warnings or notices during processing this time :(</h3>';
$error_text .= '<ul>';
foreach ($errors as $single_error) {
$error_text .= '<li class="bold">' . $single_error . '</li>';
@@ -606,9 +662,9 @@ if (0 < count($errors)) {
// 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.";
+$diff_desc = "between Transifex and git repository for $resource_type.";
if (0 < $num_of_resources_w_difference) {
- // print any differences between Transifex and our git repository
+ // print any differences between Transifex and 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)) {
@@ -620,7 +676,7 @@ if (0 < $num_of_resources_w_difference) {
}
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>';
+ echo "<p>They differs on number of untranslated strings in resources$legend:</p>";
// print a detailed strings difference table if wanted
if ($details_wanted) {
echo $table_w_details . PHP_EOL;