aboutsummaryrefslogtreecommitdiffstats
path: root/langs/lib.php
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2015-04-26 19:11:16 +0200
committerfilip <filip.komar@gmail.com>2015-04-26 19:11:16 +0200
commit1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49 (patch)
tree7fa1a8cbd095da07333e95dc60095fae108cc1d2 /langs/lib.php
parent2903bacdcdde7bf53e849c8cf86cd1c0e6561347 (diff)
downloadwww-1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49.tar
www-1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49.tar.gz
www-1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49.tar.bz2
www-1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49.tar.xz
www-1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49.zip
add capabilities to properly process l10n *.ts files like mageiaSync_en.ts
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);