aboutsummaryrefslogtreecommitdiffstats
path: root/langs/lib.php
diff options
context:
space:
mode:
Diffstat (limited to 'langs/lib.php')
-rw-r--r--langs/lib.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/langs/lib.php b/langs/lib.php
index 42183c027..5fd5f50d3 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -145,6 +145,63 @@ function _po_diff($locale, $resource, $source_l = NULL, $path = NULL)
);
}
+/**
+ * Diff English and translated ts files, to get:
+ * - source (ts) strings count
+ * - missing strings in target
+ * - untranslated strings in target
+ * - empty array for extra and duplicate strings for backward compatibility
+ *
+ * @param string $locale locale name ('sl')
+ * @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
+ *
+ * @return array
+*/
+function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL)
+{
+ $source_path_filename = sprintf('%s%s_%s.ts', $path, $resource, $locale); // mageiaSync_sl.ts
+ $source_strings = array();
+ $untranslated_strings = array();
+ $obsoleted_strings = array();
+ // read .ts file
+ $file_handle = @fopen($source_path_filename, 'r');
+ if ($file_handle === false) {
+ // Could not open file resource
+ return false;
+ }
+
+ // 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];
+ }
+ // count <translation type="unfinished"></translation> lines
+ if (false !== strpos($line, '<translation type="unfinished">')) {
+ $untranslated_strings[] = $source_string[2];
+ }
+ // count <translation type="obsolete"></translation> lines
+ if (false !== strpos($line, '<translation type="obsolete">')) {
+ array_pop($source_strings); // subtract obsoleted source strings
+ $obsoleted_strings[] = $source_string[2];
+ }
+ }
+ fclose($file_handle);
+
+ return array(
+ 'a' => count($source_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
+ 'extra' => $obsoleted_strings,
+ 'dup_str' => array(),
+ );
+}
+
/*function _lang_diff_stats($a, $b)
{
$diff = _lang_diff($a, $b);