aboutsummaryrefslogtreecommitdiffstats
path: root/langs/lib.php
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2016-10-02 16:42:41 +0200
committerfilip <filip.komar@gmail.com>2016-10-02 16:42:41 +0200
commitc3fb1b1ec8b532f97c34ef09ec62d49c162585af (patch)
tree0ae05f5922aa6677d48df6dbdcbc22453281055f /langs/lib.php
parentd8bfd2f39746d1cf2a415a41393b17161d7bea2f (diff)
downloadwww-c3fb1b1ec8b532f97c34ef09ec62d49c162585af.tar
www-c3fb1b1ec8b532f97c34ef09ec62d49c162585af.tar.gz
www-c3fb1b1ec8b532f97c34ef09ec62d49c162585af.tar.bz2
www-c3fb1b1ec8b532f97c34ef09ec62d49c162585af.tar.xz
www-c3fb1b1ec8b532f97c34ef09ec62d49c162585af.zip
separate function for parsing ts files
as preparation for working difference of ts files
Diffstat (limited to 'langs/lib.php')
-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)