aboutsummaryrefslogtreecommitdiffstats
path: root/langs
diff options
context:
space:
mode:
Diffstat (limited to 'langs')
-rw-r--r--langs/lib.php60
1 files changed, 44 insertions, 16 deletions
diff --git a/langs/lib.php b/langs/lib.php
index b00825781..263088142 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -199,12 +199,49 @@ 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);
+
+ $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'];
+
+ $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' => $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(),
+ );
+}
+
+/**
+ * Parse ts files, to get:
+ * - source (ts) strings count
+ * - source strings
+ * - untranslated strings
+ * - obsoleted strings
+ *
+ * @param string $ts_path_filename full path and filename to ts file
+ *
+ * @return array of $num_of_original_str, $source_strings, $untranslated_strings and $obsoleted_strings
+*/
+function _parse_ts_file($ts_path_filename)
+{
$source_strings = array();
$untranslated_strings = array();
$obsoleted_strings = array();
$num_of_original_str = 0;
// read .ts file
- $file_handle = @fopen($source_path_filename, 'r');
+ $file_handle = @fopen($ts_path_filename, 'r');
if ($file_handle === false) {
// Could not open file resource
return false;
@@ -238,21 +275,12 @@ function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared
}
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' => $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(),
- );
+ $parsed_ts_file['num_of_original_str'] = $num_of_original_str;
+ $parsed_ts_file['source_strings'] = $source_strings;
+ $parsed_ts_file['untranslated_strings'] = $untranslated_strings;
+ $parsed_ts_file['obsoleted_strings'] = $obsoleted_strings;
+
+ return $parsed_ts_file;
}
/*function _lang_diff_stats($a, $b)