aboutsummaryrefslogtreecommitdiffstats
path: root/langs/lib.php
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2015-08-25 23:13:42 +0200
committerfilip <filip.komar@gmail.com>2015-08-25 23:13:42 +0200
commit5764610c84d44790dff8bebfc503cb6d2b1696f7 (patch)
treed5d461cd382cafb731db98e33fccf6dd4345491a /langs/lib.php
parent142393a61e828cd3b24df992555bb38409f9aeeb (diff)
downloadwww-5764610c84d44790dff8bebfc503cb6d2b1696f7.tar
www-5764610c84d44790dff8bebfc503cb6d2b1696f7.tar.gz
www-5764610c84d44790dff8bebfc503cb6d2b1696f7.tar.bz2
www-5764610c84d44790dff8bebfc503cb6d2b1696f7.tar.xz
www-5764610c84d44790dff8bebfc503cb6d2b1696f7.zip
bugfix for mga#14899
Diffstat (limited to 'langs/lib.php')
-rw-r--r--langs/lib.php68
1 files changed, 57 insertions, 11 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