diff options
author | filip <filip.komar@gmail.com> | 2016-10-05 21:18:40 +0200 |
---|---|---|
committer | filip <filip.komar@gmail.com> | 2016-10-05 21:18:40 +0200 |
commit | e135975655eb7be56e4349724f93ec93eb1cc33d (patch) | |
tree | add65f8ac22b9f1158b725bb61e1f20dd22086ee /langs/lib.php | |
parent | 5a6dc615574a082258e8acded409a0b10d5cccb8 (diff) | |
download | www-e135975655eb7be56e4349724f93ec93eb1cc33d.tar www-e135975655eb7be56e4349724f93ec93eb1cc33d.tar.gz www-e135975655eb7be56e4349724f93ec93eb1cc33d.tar.bz2 www-e135975655eb7be56e4349724f93ec93eb1cc33d.tar.xz www-e135975655eb7be56e4349724f93ec93eb1cc33d.zip |
added parsing of ts strings in array
Diffstat (limited to 'langs/lib.php')
-rw-r--r-- | langs/lib.php | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/langs/lib.php b/langs/lib.php index 263088142..6dc27c26d 100644 --- a/langs/lib.php +++ b/langs/lib.php @@ -224,31 +224,57 @@ function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared } /** - * Parse ts files, to get: + * Parse ts files or strings in array, to get: * - source (ts) strings count * - source strings * - untranslated strings * - obsoleted strings * - * @param string $ts_path_filename full path and filename to ts file + * @param string $ts_path_filename_or_content full path and filename of ts file or strings in array in that format * * @return array of $num_of_original_str, $source_strings, $untranslated_strings and $obsoleted_strings */ -function _parse_ts_file($ts_path_filename) +function _parse_ts_file($ts_path_filename_or_content, $translation_in_file = true) { $source_strings = array(); $untranslated_strings = array(); $obsoleted_strings = array(); $num_of_original_str = 0; - // read .ts file - $file_handle = @fopen($ts_path_filename, 'r'); - if ($file_handle === false) { - // Could not open file resource - return false; + $parse_condition = true; + + if ($translation_in_file === true) { + // read .ts file + $file_handle = @fopen($ts_path_filename_or_content, 'r'); + if ($file_handle === false) { + // Could not open file resource + return false; + } + } else { + if (!is_array($ts_path_filename_or_content) || empty($ts_path_filename_or_content)) { + // given translation not valid + return false; + } + $translation_in_file = false; } // iterate over lines - while(($line = fgets($file_handle, 65536)) !== false) { + while($parse_condition) { + // output and test line for translation in file + if ($translation_in_file) { + if (($line = fgets($file_handle, 65536)) === false) { + $parse_condition = false; + continue; + } + // output and test line for translation in array + } else { + $line = current($ts_path_filename_or_content); + $end_array_test = next($ts_path_filename_or_content); + if (false === $end_array_test) { + $parse_condition = false; + continue; + } + } + // store context name if (false !== strpos($line, '</name>')) { preg_match_all("/(<name>)(.+)(<\/name>)/", $line, $context_name); @@ -273,7 +299,9 @@ function _parse_ts_file($ts_path_filename) $obsoleted_strings[] = $source_string[2][0] . ' context_name: '. $context_name[2][0]; } } - fclose($file_handle); + if ($translation_in_file) { + fclose($file_handle); + } $parsed_ts_file['num_of_original_str'] = $num_of_original_str; $parsed_ts_file['source_strings'] = $source_strings; |