diff options
Diffstat (limited to 'langs/lib.php')
-rw-r--r-- | langs/lib.php | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/langs/lib.php b/langs/lib.php index dc4dbd8a4..1b016c8a4 100644 --- a/langs/lib.php +++ b/langs/lib.php @@ -129,16 +129,14 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared // process $target_l translation if (!isset($target_l[$msgid])) { - // adding fuzzy or missing string or plurals - $fuzzy_or_missing[$msgid] = $subarray; + // adding fuzzy or missing string + $fuzzy_or_missing[] = $msgid; $msgstr_target_l = NULL; } else { $msgstr_target_l = $target_l[$msgid][$context_or_num]; // are there any plurals untranslated? $untranslated_plural_target_l = FALSE; if (!is_null($msgid_plural)) { - // filter out msgid_plural - unset($msgstr_target_l['msgid_plural']); foreach ($msgstr_target_l as $nplural) { if (empty($nplural)) { $untranslated_plural_target_l = TRUE; @@ -147,7 +145,7 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared } // untranslated string if ($untranslated_plural_target_l || empty($msgstr_target_l[0])) { - $untrans[$msgid] = $subarray; // adding untranslated string or plurals + $untrans[] = $msgid; // adding untranslated string } } @@ -161,8 +159,8 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared $msgstr_compared[0] = ''; } if ($msgstr_target_l != $msgstr_compared) { - $differences[$msgid]['target_l'][$context_or_num] = $msgstr_target_l; - $differences[$msgid]['compared'][$context_or_num] = $msgstr_compared; + $differences[$msgid][$context_or_num]['target_l'] = $msgstr_target_l; + $differences[$msgid][$context_or_num]['compared'] = $msgstr_compared; } } } @@ -191,15 +189,17 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared * @param string $resource file name ('mageiaSync') * @param array $source_l array with source file strings (to avoid duplicated parsing) * @param string $path directly passed path for nonlocal files + * @param array $compared array with strings for comparing * * @return array */ -function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL) +function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared = NULL) { $source_path_filename = sprintf('%s%s_%s.ts', $path, $resource, $locale); // mageiaSync_sl.ts $source_strings = array(); $untranslated_strings = array(); $obsoleted_strings = array(); + $num_of_original_str = 0; // read .ts file $file_handle = @fopen($source_path_filename, 'r'); if ($file_handle === false) { @@ -209,29 +209,44 @@ function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL) // iterate over lines while(($line = fgets($file_handle, 65536)) !== false) { - // count <source>???</source> lines - if (false !== strpos($line, '</source>')) { - preg_match_all("/(<source>)([a-z_A-Z@-]+)(<\/source>)/", $line, $source_string); - $source_strings[] = $source_string[2]; + // store context name + if (false !== strpos($line, '</name>')) { + preg_match_all("/(<name>)(.+)(<\/name>)/", $line, $context_name); + } + // store source lines + else if (false !== strpos($line, '</source>')) { + preg_match_all("/(<source>)(.+)(<\/source>)/", $line, $source_string); + $num_of_original_str++; } - // count <translation type="unfinished"></translation> lines - if (false !== strpos($line, '<translation type="unfinished"')) { - $untranslated_strings[] = $source_string[2]; + // store translations + else if (false !== strpos($line, '<translation>')) { + preg_match_all("/(<translation>)(.+)(<\/translation>)/", $line, $translation_string); + $source_strings[$source_string[2][0]][$context_name[2][0]] = $translation_string[2]; } - // count <translation type="obsolete"></translation> lines - if (false !== strpos($line, '<translation type="obsolete"')) { + // store untranslated string + else if (false !== strpos($line, '<translation type="unfinished"')) { + $untranslated_strings[] = $source_string[2][0] . ' context_name: '. $context_name[2][0]; + } + // store obsolete translation + else if (false !== strpos($line, '<translation type="obsolete"')) { array_pop($source_strings); // subtract obsoleted source strings - $obsoleted_strings[] = $source_string[2]; + $obsoleted_strings[] = $source_string[2][0] . ' context_name: '. $context_name[2][0]; } } fclose($file_handle); + $differences = array(); + // TODO check if $source_strings and $compared are the same format +// $not_in_compared = array_diff($source_strings, $compared); +// $not_in_source = array_diff($compared, $source_strings); + // TODO join $not_in_compared and $not_in_source to $differences with foreach of passed $source_l return array( - 'a' => count($source_strings), // # of original strings + 'a' => $num_of_original_str - count($obsoleted_strings), // # of original strings // 'b' => , // # of target strings 'source_strings' => $source_strings, // array of original strings 'fuzzy_or_missing' => array(), // array of fuzzy or missing strings 'notrans' => $untranslated_strings, // array of untranslated strings + 'differences' => $differences, // array of different strings from two translations 'extra' => $obsoleted_strings, 'dup_str' => array(), ); |