aboutsummaryrefslogtreecommitdiffstats
path: root/langs
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2016-10-11 21:52:42 +0200
committerfilip <filip.komar@gmail.com>2016-10-11 21:52:42 +0200
commit6c78b8851d1decc4e84195a6d972d0501c6685e4 (patch)
tree7acc3ff7b4e25d766e4a0609a7b200ec5c3d7b23 /langs
parente135975655eb7be56e4349724f93ec93eb1cc33d (diff)
downloadwww-6c78b8851d1decc4e84195a6d972d0501c6685e4.tar
www-6c78b8851d1decc4e84195a6d972d0501c6685e4.tar.gz
www-6c78b8851d1decc4e84195a6d972d0501c6685e4.tar.bz2
www-6c78b8851d1decc4e84195a6d972d0501c6685e4.tar.xz
www-6c78b8851d1decc4e84195a6d972d0501c6685e4.zip
finally treat TS files properly in TX/git diff report
Diffstat (limited to 'langs')
-rw-r--r--langs/lib.php66
-rw-r--r--langs/report_tx_git.php6
2 files changed, 52 insertions, 20 deletions
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, '<translation>')) {
+ 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];
- }
- // 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][0] . ' context_name: '. $context_name[2][0];
+ // store untranslated string
+ if (false !== strpos($line, 'type="unfinished"')) {
+ $untranslated_strings[] = $source_string[2][0] . ' context_name: '. $context_name[2][0];
+ }
+ // store obsolete translation
+ else if (false !== strpos($line, 'type="obsolete"')) {
+ $obsoleted_strings[] = $source_string[2][0] . ' context_name: '. $context_name[2][0];
+ }
}
}
if ($translation_in_file) {
fclose($file_handle);
}
- $parsed_ts_file['num_of_original_str'] = $num_of_original_str;
+ $parsed_ts_file['num_of_original_str'] = $num_of_original_str - count($obsoleted_strings);
$parsed_ts_file['source_strings'] = $source_strings;
$parsed_ts_file['untranslated_strings'] = $untranslated_strings;
$parsed_ts_file['obsoleted_strings'] = $obsoleted_strings;
@@ -720,7 +748,7 @@ function generating_report($language_codes, $resource_names, $path = NULL, $pot_
// treat TS files differently
if (false !== strpos($pot_name, '_en.ts')) {
$partial_pot_name = substr($pot_name, 0, -6); // cuts '_en.ts' from mageiaSync_en.ts
- $stat = _ts_diff($l, $partial_pot_name, $source_strings, $path);
+ $stat = _ts_diff($l, $partial_pot_name, $source_strings, $path, $compared);
} else {
$stat = _po_diff($l, $resource, $source_strings, $path, $compared);
}
diff --git a/langs/report_tx_git.php b/langs/report_tx_git.php
index 5de51deff..d6f108b15 100644
--- a/langs/report_tx_git.php
+++ b/langs/report_tx_git.php
@@ -77,7 +77,11 @@ if ($details_wanted) {
if (!empty($tx_file)) {
$tx_file_content = $tx_file['content'];
$tx_file_content = explode("\n", $tx_file_content);
- $parsed_tx_file_content = phpmo_parse_po_file($tx_file_content, FALSE);
+ if ('mageiasync' == $wanted_resource_name) { // treat TS files differently
+ $parsed_tx_file_content = _parse_ts_file($tx_file_content, FALSE);
+ } else {
+ $parsed_tx_file_content = phpmo_parse_po_file($tx_file_content, FALSE);
+ }
}
}