diff options
-rw-r--r-- | langs/report_tx_git.php | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/langs/report_tx_git.php b/langs/report_tx_git.php index 2baf6bda0..5d0490bcb 100644 --- a/langs/report_tx_git.php +++ b/langs/report_tx_git.php @@ -261,17 +261,46 @@ function tx_call($tx_request, $project = 'project/mageia/') $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_json_error'] = "$error Please reload the page and report this on mailing list if it persist."; + $errors['tx_json_error'] = "$error Please reload the page later and report this on mailing list if it persist."; $tx_result_array = array(); } else if (FALSE === $tx_result) { $error = "API call to Transifex $tx_request failed."; - $errors['tx_call'] = "$error Please reload the page and report this on mailing list if it persist."; + $errors['tx_call'] = "$error Please reload the page later and report this on mailing list if it persist."; $tx_result_array = array(); } return $tx_result_array; } /** + * Convert git resource name to Transifex one or reverse + * + * @param string $resource_name like 'about/constitution' (git name) + * @param string $category like 'Webpages', 'Cauldron' or 'Documentation' + * @param boolean $tx_to_git_name_conversion direction of conversion + * + * @return string $resource_name like 'page-about-constitution' (tx name) +*/ +function resource_name_conversion($resource_name, $category = '', $tx_to_git_name_conversion = FALSE) +{ + $tx_names = array('/', 'mageia-welcome', 'identity-catdap'); + $git_names = array('-', 'Mageia%20Welcome', 'Identity%20(CatDap)'); + if ($tx_to_git_name_conversion) { + $resource_name = str_replace($tx_names, $git_names, $resource_name); + } else { + $resource_name = str_replace($git_names, $tx_names, $resource_name); + } + if ('Webpages' == $category) { + if ($tx_to_git_name_conversion) { + $resource_name = str_replace('page-', '', $resource_name); + } else { + $resource_name = 'page-' . $resource_name; + } + } + + return $resource_name; +} + +/** * Build Transifex and git links with numbers of untranslated strings * * Returns text string @@ -285,9 +314,7 @@ function tx_call($tx_request, $project = 'project/mageia/') */ function build_links($git_resource_name, $language_code, $resource_type, $stat_data) { - $search_array = array('/', 'mageia-welcome', 'identity-catdap'); - $replace_array = array('-', 'Mageia%20Welcome', 'Identity%20(CatDap)'); - $tx_resource_name = str_replace($search_array, $replace_array, $git_resource_name); + $tx_resource_name = resource_name_conversion($git_resource_name); $locale_name = locale_underscore_to_hyphen($language_code); if ('Webpages' == $resource_type) { if ('nav' == $git_resource_name) { @@ -462,6 +489,7 @@ $tx_resources = tx_call("resources"); // 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]; @@ -684,7 +712,7 @@ if (0 < count($parse_errors)) { 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 and report this on mailing list if it persist."; + $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"; } @@ -696,10 +724,10 @@ if (0 < count($nonequal_num_of_all_strings)) { // making a list of resources with Tx/git differences ksort($tx_git_difference); -$all_languages_with_tx_git_diff = array(); +// $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; +// $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; } @@ -708,9 +736,12 @@ $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); +// 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(); @@ -727,9 +758,14 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o $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(); + 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); @@ -754,11 +790,6 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o $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; @@ -766,9 +797,12 @@ if (0 < $num_of_resources_w_difference && $num_for_switch_table_to_list > $num_o $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 = ''; -if (0 < $num_of_resources_w_difference) { +$list_num_diff = FALSE; +if (0 < $num_of_resources_w_difference && !$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) { @@ -883,9 +917,9 @@ if (0 < $num_of_resources_w_difference) { 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 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) { + if ($table_num_diff) { echo $table_difference . PHP_EOL; - } else { + } 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; |