From 6c78b8851d1decc4e84195a6d972d0501c6685e4 Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 11 Oct 2016 21:52:42 +0200 Subject: finally treat TS files properly in TX/git diff report --- langs/lib.php | 66 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 19 deletions(-) (limited to 'langs/lib.php') diff --git a/langs/lib.php b/langs/lib.php index 6dc27c26d..1e1b67413 100644 --- a/langs/lib.php +++ b/langs/lib.php @@ -198,21 +198,50 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared */ 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 - $parsed_ts_file = _parse_ts_file($source_path_filename); + if (NULL == $source_l) { + $source_ts_file = _parse_ts_file(sprintf('%s%s_en.ts', $path, $resource)); // mageiaSync_en.ts + if (FALSE == $source_ts_file) { + $source_ts_file = array('source_strings' => array(array())); + } + $source_l = $source_ts_file['source_strings']; + } - $num_of_original_str = $parsed_ts_file['num_of_original_str']; - $source_strings = $parsed_ts_file['source_strings']; - $untranslated_strings = $parsed_ts_file['untranslated_strings']; - $obsoleted_strings = $parsed_ts_file['obsoleted_strings']; + $target_ts_file = _parse_ts_file(sprintf('%s%s_%s.ts', $path, $resource, $locale)); // mageiaSync_sl.ts + + $num_of_original_str = $target_ts_file['num_of_original_str']; + $source_strings = $target_ts_file['source_strings']; + $untranslated_strings = $target_ts_file['untranslated_strings']; + $obsoleted_strings = $target_ts_file['obsoleted_strings']; $differences = array(); + foreach ($source_l as $msgid => $subarray) { + foreach ($subarray as $context_or_num => $msgstr_subarray) { + if (!isset($source_strings[$msgid])) { + $msgstr_target_l[0] = ''; + } else { + $msgstr_target_l = $source_strings[$msgid][$context_or_num]; + } + // process $compared translation + if (!is_null($compared)) { + // if there is a translation for this string in $compared + if (isset($compared['source_strings'][$msgid][$context_or_num])) { + $msgstr_compared = $compared['source_strings'][$msgid][$context_or_num]; + } else { + $msgstr_compared[0] = ''; + } + if ($msgstr_target_l != $msgstr_compared) { + $differences[$msgid][$context_or_num]['target_l'] = $msgstr_target_l; + $differences[$msgid][$context_or_num]['compared'] = $msgstr_compared; + } + } + } + } // 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' => $num_of_original_str - count($obsoleted_strings), // # of original strings + 'a' => $num_of_original_str, // 'b' => , // # of target strings 'source_strings' => $source_strings, // array of original strings 'fuzzy_or_missing' => array(), // array of fuzzy or missing strings @@ -285,25 +314,24 @@ function _parse_ts_file($ts_path_filename_or_content, $translation_in_file = tru $num_of_original_str++; } // store translations - else if (false !== strpos($line, '')) { + else if (false !== strpos($line, ')(.+)(<\/translation>)/", $line, $translation_string); $source_strings[$source_string[2][0]][$context_name[2][0]] = $translation_string[2]; - } - // store untranslated string - else if (false !== strpos($line, '