diff options
-rw-r--r-- | langs/lib.php | 68 | ||||
-rw-r--r-- | langs/report_tx_git.php | 4 |
2 files changed, 58 insertions, 14 deletions
diff --git a/langs/lib.php b/langs/lib.php index f28ae30f9..73ef44ced 100644 --- a/langs/lib.php +++ b/langs/lib.php @@ -104,38 +104,84 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL) } } - $pot_strings = array(); - $untrans = array(); + $pot_strings = array(); + $untrans = array(); $fuzzy_or_missing = array(); + $num_of_original_strings = 0; if (FALSE != $source_l) { foreach ($source_l as $escaped_string => $subarray) { if (!empty($subarray["msgid"])) { // filter out header - $pot_strings[$escaped_string] = $subarray["msgid"]; + $msgctxt = array(); + foreach ($subarray["msgstr"] as $key => $unused) { + if (isset($subarray["msgctxt"][$key])) { + $msgctxt[$key] = $subarray["msgctxt"][$key]; + } else { + $msgctxt[$key] = TRUE; + } + $num_of_original_strings++; + } + $pot_strings[$escaped_string] = $msgctxt; } } } + $fuzzy_or_missing = $pot_strings; + $untrans = $pot_strings; + if (FALSE != $target_l) { foreach ($target_l as $escaped_string => $subarray) { if (!empty($subarray["msgid"])) { // filter out header - $po_strings[$escaped_string] = $subarray["msgstr"][0]; + foreach ($subarray["msgstr"] as $key => $msgstr) { + // remove present string + unset($fuzzy_or_missing[$escaped_string][$key]); + if (!empty($msgstr)) { + // remove translated string + if(is_array($msgstr)) { // are there any plural strings present? + $erase_plural_key = TRUE; + foreach ($msgstr as $nplural) { + if (empty($nplural)) { + $erase_plural_key = FALSE; + } + } + // if all plural keys are translated, remove msgstr for that msgid + if ($erase_plural_key) { + unset($untrans[$escaped_string][$key]); + } + } else { + unset($untrans[$escaped_string][$key]); + } + } + } } } } - foreach ($pot_strings as $escaped_string => $translated_string) { - if (isset($po_strings[$escaped_string])) { - if (empty($po_strings[$escaped_string])) { - $untrans[] = $escaped_string; + $arrays = array($fuzzy_or_missing, $untrans); + foreach ($arrays as &$current_array) { + $strings = array(); + $cnt = 0; + foreach ($current_array as $escaped_string => $msgctxt) { + if(!empty($msgctxt)) { + $keys = array_keys($msgctxt); + if(is_numeric($keys[0])) { + $index = $cnt; + } else { + $index = $keys[0]; + } + $strings[$index] = $escaped_string; + $cnt++; } - } else { - $fuzzy_or_missing[] = $escaped_string; } + $current_array = $strings; } + unset($current_array); + + list($fuzzy_or_missing, $untrans) = $arrays; + $untrans = array_diff($untrans, $fuzzy_or_missing); return array( - 'a' => count($pot_strings), // # of original strings + 'a' => $num_of_original_strings, // # of original strings // 'b' => count($po_strings), // # of target strings 'source_strings' => $source_l, // array of original strings 'fuzzy_or_missing' => $fuzzy_or_missing, // array of fuzzy or missing strings diff --git a/langs/report_tx_git.php b/langs/report_tx_git.php index f6f3828a1..59939a134 100644 --- a/langs/report_tx_git.php +++ b/langs/report_tx_git.php @@ -696,9 +696,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."; - $bug = "Note that there is a <a href=\"https://bugs.mageia.org/show_bug.cgi?id=14899\">"; - $bug .= "known bug which influence proper parsing of msec and mageia-kde-translation</a>."; - $errors['nonequal_num_of_all_strings'] = "$error Please report that on the mailing list if it happens across several days. $bug"; + $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 |