Changeset 18528
- Timestamp:
- 08/11/2011 04:29:35 AM (14 years ago)
- Location:
- trunk/wp-includes/pomo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/pomo/entry.php
r13228 r18528 3 3 * Contains Translation_Entry class 4 4 * 5 * @version $Id: entry.php 406 2010-02-07 11:10:24Z nbachiyski $5 * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage entry … … 66 66 return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular; 67 67 } 68 69 function merge_with(&$other) { 70 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); 71 $this->references = array_unique( array_merge( $this->references, $other->references ) ); 72 if ( $this->extracted_comments != $other->extracted_comments ) { 73 $this->extracted_comments .= $other->extracted_comments; 74 } 75 76 } 68 77 } 69 78 endif; -
trunk/wp-includes/pomo/mo.php
r13830 r18528 3 3 * Class for working with MO files 4 4 * 5 * @version $Id: mo.php 406 2010-02-07 11:10:24Z nbachiyski $5 * @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage mo … … 31 31 $fh = fopen($filename, 'wb'); 32 32 if ( !$fh ) return false; 33 $res = $this->export_to_file_handle( $fh ); 34 fclose($fh); 35 return $res; 36 } 37 38 function export() { 39 $tmp_fh = fopen("php://temp", 'r+'); 40 if ( !$tmp_fh ) return false; 41 $this->export_to_file_handle( $tmp_fh ); 42 rewind( $tmp_fh ); 43 return stream_get_contents( $tmp_fh ); 44 } 45 46 function export_to_file_handle($fh) { 33 47 $entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);')); 34 48 ksort($entries); … … 44 58 $translations_lenghts_addr, $size_of_hash, $hash_addr)); 45 59 fseek($fh, $originals_lenghts_addr); 46 60 47 61 // headers' msgid is an empty string 48 62 fwrite($fh, pack('VV', 0, $current_addr)); … … 56 70 $current_addr += $length + 1; // account for the NULL byte after 57 71 } 58 72 59 73 $exported_headers = $this->export_headers(); 60 74 fwrite($fh, pack('VV', strlen($exported_headers), $current_addr)); 61 75 $current_addr += strlen($exported_headers) + 1; 62 76 $translations_table = $exported_headers . chr(0); 63 77 64 78 foreach($entries as $entry) { 65 79 $translations_table .= $this->export_translations($entry) . chr(0); … … 68 82 $current_addr += $length + 1; 69 83 } 70 84 71 85 fwrite($fh, $originals_table); 72 86 fwrite($fh, $translations_table); 73 fclose($fh);74 } 75 87 return true; 88 } 89 76 90 function export_original($entry) { 77 91 //TODO: warnings for control characters … … 81 95 return $exported; 82 96 } 83 97 84 98 function export_translations($entry) { 85 99 //TODO: warnings for control characters 86 100 return implode(chr(0), $entry->translations); 87 101 } 88 102 89 103 function export_headers() { 90 104 $exported = ''; … … 194 208 * Build a Translation_Entry from original string and translation strings, 195 209 * found in a MO file 196 * 210 * 197 211 * @static 198 212 * @param string $original original string to translate from MO file. Might contain -
trunk/wp-includes/pomo/po.php
r13830 r18528 3 3 * Class for working with PO files 4 4 * 5 * @version $Id: po.php 406 2010-02-07 11:10:24Z nbachiyski $5 * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage po … … 19 19 if ( !class_exists( 'PO' ) ): 20 20 class PO extends Gettext_Translations { 21 21 22 var $comments_before_headers = ''; 22 23 23 24 /** … … 32 33 } 33 34 $poified = PO::poify($header_string); 34 return rtrim("msgid \"\"\nmsgstr $poified"); 35 if ($this->comments_before_headers) 36 $before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# '); 37 else 38 $before_headers = ''; 39 return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified"); 35 40 } 36 41 … … 76 81 return fclose($fh); 77 82 } 83 84 /** 85 * Text to include as a comment before the start of the PO contents 86 * 87 * Doesn't need to include # in the beginning of lines, these are added automatically 88 */ 89 function set_comment_before_headers( $text ) { 90 $this->comments_before_headers = $text; 91 } 78 92 79 93 /** … … 107 121 return $po; 108 122 } 109 123 110 124 /** 111 125 * Gives back the original string from a PO-formatted string 112 * 126 * 113 127 * @static 114 128 * @param string $string PO-formatted string … … 140 154 141 155 /** 142 * Inserts $with in the beginning of every new line of $string and 156 * Inserts $with in the beginning of every new line of $string and 143 157 * returns the modified string 144 158 * … … 218 232 return $res !== false; 219 233 } 220 234 221 235 function read_entry($f, $lineno = 0) { 222 236 $entry = new Translation_Entry(); … … 255 269 } 256 270 // add comment 257 $this->add_comment_to_entry($entry, $line); 271 $this->add_comment_to_entry($entry, $line);; 258 272 } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) { 259 273 if ($is_final($context)) { … … 323 337 return array('entry' => $entry, 'lineno' => $lineno); 324 338 } 325 339 326 340 function read_line($f, $action = 'read') { 327 341 static $last_line = ''; … … 340 354 return $line; 341 355 } 342 356 343 357 function add_comment_to_entry(&$entry, $po_comment_line) { 344 358 $first_two = substr($po_comment_line, 0, 2); … … 354 368 } 355 369 } 356 370 357 371 function trim_quotes($s) { 358 372 if ( substr($s, 0, 1) == '"') $s = substr($s, 1); -
trunk/wp-includes/pomo/streams.php
r15590 r18528 4 4 * Based on the classes from Danilo Segan <danilo@kvota.net> 5 5 * 6 * @version $Id: streams.php 406 2010-02-07 11:10:24Z nbachiyski $6 * @version $Id: streams.php 597 2011-01-16 20:14:36Z nbachiyski $ 7 7 * @package pomo 8 8 * @subpackage streams … … 11 11 if ( !class_exists( 'POMO_Reader' ) ): 12 12 class POMO_Reader { 13 13 14 14 var $endian = 'little'; 15 15 var $_post = ''; 16 16 17 17 function POMO_Reader() { 18 18 $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); 19 19 $this->_pos = 0; 20 20 } 21 21 22 22 /** 23 23 * Sets the endianness of the file. 24 24 * 25 * @param string $endian'big' or 'little'25 * @param $endian string 'big' or 'little' 26 26 */ 27 27 function setEndian($endian) { … … 58 58 return unpack($endian_letter.$count, $bytes); 59 59 } 60 61 60 61 62 62 function substr($string, $start, $length) { 63 63 if ($this->is_overloaded) { … … 67 67 } 68 68 } 69 69 70 70 function strlen($string) { 71 71 if ($this->is_overloaded) { … … 75 75 } 76 76 } 77 77 78 78 function str_split($string, $chunk_size) { 79 79 if (!function_exists('str_split')) { … … 87 87 } 88 88 } 89 90 89 90 91 91 function pos() { 92 92 return $this->_pos; … … 96 96 return true; 97 97 } 98 98 99 99 function close() { 100 100 return true; … … 107 107 function POMO_FileReader($filename) { 108 108 parent::POMO_Reader(); 109 $this->_f = fopen($filename, 'r ');110 } 111 109 $this->_f = fopen($filename, 'rb'); 110 } 111 112 112 function read($bytes) { 113 113 return fread($this->_f, $bytes); 114 114 } 115 115 116 116 function seekto($pos) { 117 117 if ( -1 == fseek($this->_f, $pos, SEEK_SET)) { … … 121 121 return true; 122 122 } 123 123 124 124 function is_resource() { 125 125 return is_resource($this->_f); 126 126 } 127 127 128 128 function feof() { 129 129 return feof($this->_f); 130 130 } 131 131 132 132 function close() { 133 133 return fclose($this->_f); 134 134 } 135 135 136 136 function read_all() { 137 137 $all = ''; … … 149 149 */ 150 150 class POMO_StringReader extends POMO_Reader { 151 151 152 152 var $_str = ''; 153 153 154 154 function POMO_StringReader($str = '') { 155 155 parent::POMO_Reader(); … … 179 179 return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str)); 180 180 } 181 181 182 182 } 183 183 endif; -
trunk/wp-includes/pomo/translations.php
r13830 r18528 3 3 * Class for a set of entries for translation and their associated headers 4 4 * 5 * @version $Id: translations.php 406 2010-02-07 11:10:24Z nbachiyski $5 * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage translations … … 28 28 if (false === $key) return false; 29 29 $this->entries[$key] = &$entry; 30 return true; 31 } 32 33 function add_entry_or_merge($entry) { 34 if (is_array($entry)) { 35 $entry = new Translation_Entry($entry); 36 } 37 $key = $entry->key(); 38 if (false === $key) return false; 39 if (isset($this->entries[$key])) 40 $this->entries[$key]->merge_with($entry); 41 else 42 $this->entries[$key] = &$entry; 30 43 return true; 31 44 } … … 109 122 } 110 123 } 124 125 function merge_originals_with(&$other) { 126 foreach( $other->entries as $entry ) { 127 if ( !isset( $this->entries[$entry->key()] ) ) 128 $this->entries[$entry->key()] = $entry; 129 else 130 $this->entries[$entry->key()]->merge_with($entry); 131 } 132 } 111 133 } 112 134 … … 127 149 return call_user_func($this->_gettext_select_plural_form, $count); 128 150 } 129 151 130 152 function nplurals_and_expression_from_header($header) { 131 153 if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { … … 153 175 * Adds parantheses to the inner parts of ternary operators in 154 176 * plural expressions, because PHP evaluates ternary oerators from left to right 155 * 177 * 156 178 * @param string $expression the expression without parentheses 157 179 * @return string the expression with parentheses added … … 181 203 return rtrim($res, ';'); 182 204 } 183 205 184 206 function make_headers($translation) { 185 207 $headers = array(); … … 194 216 return $headers; 195 217 } 196 218 197 219 function set_header($header, $value) { 198 220 parent::set_header($header, $value); … … 213 235 var $entries = array(); 214 236 var $headers = array(); 215 237 216 238 function add_entry($entry) { 217 239 return true;
Note: See TracChangeset
for help on using the changeset viewer.