From 1fb8dd20b4f298dbe1e1f20b7521b8386fb5af49 Mon Sep 17 00:00:00 2001 From: filip Date: Sun, 26 Apr 2015 19:11:16 +0200 Subject: add capabilities to properly process l10n *.ts files like mageiaSync_en.ts --- langs/lib.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'langs/lib.php') 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 ??? lines + if (false !== strpos($line, '')) { + preg_match_all("/()([a-z_A-Z@-]+)(<\/source>)/", $line, $source_string); + $source_strings[] = $source_string[2]; + } + // count lines + if (false !== strpos($line, '')) { + $untranslated_strings[] = $source_string[2]; + } + // count lines + if (false !== strpos($line, '')) { + 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); -- cgit v1.2.1