Changeset 22349
- Timestamp:
- 10/31/2012 10:13:51 PM (12 years ago)
- Location:
- trunk/wp-includes/pomo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/pomo/entry.php
r18528 r22349 3 3 * Contains Translation_Entry class 4 4 * 5 * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $5 * @version $Id: entry.php 718 2012-10-31 00:32:02Z 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 68 69 69 function merge_with(&$other) { 70 70 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); … … 73 73 $this->extracted_comments .= $other->extracted_comments; 74 74 } 75 75 76 76 } 77 77 } -
trunk/wp-includes/pomo/mo.php
r21793 r22349 3 3 * Class for working with MO files 4 4 * 5 * @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $5 * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage mo … … 35 35 return $res; 36 36 } 37 37 38 38 function export() { 39 39 $tmp_fh = fopen("php://temp", 'r+'); … … 43 43 return stream_get_contents( $tmp_fh ); 44 44 } 45 45 46 function is_entry_good_for_export( $entry ) { 47 if ( empty( $entry->translations ) ) { 48 return false; 49 } 50 51 if ( !array_filter( $entry->translations ) ) { 52 return false; 53 } 54 55 return true; 56 } 57 46 58 function export_to_file_handle($fh) { 47 $entries = array_filter( $this->entries, create_function('$e', 'return !empty($e->translations);'));59 $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); 48 60 ksort($entries); 49 61 $magic = 0x950412de; … … 58 70 $translations_lenghts_addr, $size_of_hash, $hash_addr)); 59 71 fseek($fh, $originals_lenghts_addr); 60 72 61 73 // headers' msgid is an empty string 62 74 fwrite($fh, pack('VV', 0, $current_addr)); … … 70 82 $current_addr += $length + 1; // account for the NULL byte after 71 83 } 72 84 73 85 $exported_headers = $this->export_headers(); 74 86 fwrite($fh, pack('VV', strlen($exported_headers), $current_addr)); 75 87 $current_addr += strlen($exported_headers) + 1; 76 88 $translations_table = $exported_headers . chr(0); 77 89 78 90 foreach($entries as $entry) { 79 91 $translations_table .= $this->export_translations($entry) . chr(0); … … 82 94 $current_addr += $length + 1; 83 95 } 84 96 85 97 fwrite($fh, $originals_table); 86 98 fwrite($fh, $translations_table); 87 99 return true; 88 100 } 89 101 90 102 function export_original($entry) { 91 103 //TODO: warnings for control characters … … 95 107 return $exported; 96 108 } 97 109 98 110 function export_translations($entry) { 99 111 //TODO: warnings for control characters 100 112 return implode(chr(0), $entry->translations); 101 113 } 102 114 103 115 function export_headers() { 104 116 $exported = ''; … … 196 208 197 209 if ('' === $original) { 198 $headers = $this->make_headers($translation); 199 $this->set_headers($headers); 210 $this->set_headers($this->make_headers($translation)); 200 211 } else { 201 212 $entry = &$this->make_entry($original, $translation); … … 209 220 * Build a Translation_Entry from original string and translation strings, 210 221 * found in a MO file 211 * 222 * 212 223 * @static 213 224 * @param string $original original string to translate from MO file. Might contain -
trunk/wp-includes/pomo/po.php
r18528 r22349 3 3 * Class for working with PO files 4 4 * 5 * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $5 * @version $Id: po.php 718 2012-10-31 00:32:02Z 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 22 var $comments_before_headers = ''; 23 23 … … 81 81 return fclose($fh); 82 82 } 83 83 84 84 /** 85 85 * Text to include as a comment before the start of the PO contents 86 * 86 * 87 87 * Doesn't need to include # in the beginning of lines, these are added automatically 88 88 */ … … 121 121 return $po; 122 122 } 123 123 124 124 /** 125 125 * Gives back the original string from a PO-formatted string 126 * 126 * 127 127 * @static 128 128 * @param string $string PO-formatted string … … 154 154 155 155 /** 156 * 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 157 157 * returns the modified string 158 158 * … … 230 230 } 231 231 PO::read_line($f, 'clear'); 232 return $res !== false; 233 } 234 232 if ( false === $res ) { 233 return false; 234 } 235 if ( ! $this->headers && ! $this->entries ) { 236 return false; 237 } 238 return true; 239 } 240 235 241 function read_entry($f, $lineno = 0) { 236 242 $entry = new Translation_Entry(); … … 337 343 return array('entry' => $entry, 'lineno' => $lineno); 338 344 } 339 345 340 346 function read_line($f, $action = 'read') { 341 347 static $last_line = ''; … … 350 356 } 351 357 $line = $use_last_line? $last_line : fgets($f); 358 $line = gp_endswith( $line, "\r\n" )? rtrim( $line, "\r\n" ) . "\n" : $line; 352 359 $last_line = $line; 353 360 $use_last_line = false; 354 361 return $line; 355 362 } 356 363 357 364 function add_comment_to_entry(&$entry, $po_comment_line) { 358 365 $first_two = substr($po_comment_line, 0, 2); … … 368 375 } 369 376 } 370 377 371 378 function trim_quotes($s) { 372 379 if ( substr($s, 0, 1) == '"') $s = substr($s, 1); -
trunk/wp-includes/pomo/streams.php
r18528 r22349 4 4 * Based on the classes from Danilo Segan <danilo@kvota.net> 5 5 * 6 * @version $Id: streams.php 597 2011-01-16 20:14:36Z nbachiyski $6 * @version $Id: streams.php 718 2012-10-31 00:32:02Z 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. … … 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; … … 109 109 $this->_f = fopen($filename, 'rb'); 110 110 } 111 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
r18827 r22349 3 3 * Class for a set of entries for translation and their associated headers 4 4 * 5 * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $5 * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage translations … … 30 30 return true; 31 31 } 32 32 33 33 function add_entry_or_merge($entry) { 34 34 if (is_array($entry)) { … … 82 82 * Given the number of items, returns the 0-based index of the plural form to use 83 83 * 84 * Here, in the base Translations class, the common logic for English is impl emented:84 * Here, in the base Translations class, the common logic for English is implmented: 85 85 * 0 if there is one element, 1 otherwise 86 86 * … … 122 122 } 123 123 } 124 124 125 125 function merge_originals_with(&$other) { 126 126 foreach( $other->entries as $entry ) { … … 149 149 return call_user_func($this->_gettext_select_plural_form, $count); 150 150 } 151 151 152 152 function nplurals_and_expression_from_header($header) { 153 153 if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { … … 175 175 * Adds parantheses to the inner parts of ternary operators in 176 176 * plural expressions, because PHP evaluates ternary oerators from left to right 177 * 177 * 178 178 * @param string $expression the expression without parentheses 179 179 * @return string the expression with parentheses added … … 203 203 return rtrim($res, ';'); 204 204 } 205 205 206 206 function make_headers($translation) { 207 207 $headers = array(); … … 216 216 return $headers; 217 217 } 218 218 219 219 function set_header($header, $value) { 220 220 parent::set_header($header, $value); … … 235 235 var $entries = array(); 236 236 var $headers = array(); 237 237 238 238 function add_entry($entry) { 239 239 return true;
Note: See TracChangeset
for help on using the changeset viewer.