Changeset 12079
- Timestamp:
- 10/21/2009 07:06:55 AM (15 years ago)
- Location:
- trunk/wp-includes/pomo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/pomo/entry.php
r11626 r12079 3 3 * Contains Translation_Entry class 4 4 * 5 * @version $Id: entry.php 115 2009-05-11 18:56:15Z nbachiyski $5 * @version $Id: entry.php 222 2009-09-07 21:14:23Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage entry 8 8 */ 9 9 10 10 if ( !class_exists( 'Translation_Entry' ) ): 11 11 /** 12 12 * Translation_Entry class encapsulates a translatable string … … 68 68 } 69 69 } 70 ?> 70 endif; -
trunk/wp-includes/pomo/mo.php
r11626 r12079 3 3 * Class for working with MO files 4 4 * 5 * @version $Id: mo.php 106 2009-04-23 19:48:22Z nbachiyski $5 * @version $Id: mo.php 221 2009-09-07 21:08:21Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage mo … … 11 11 require_once dirname(__FILE__) . '/streams.php'; 12 12 13 if ( !class_exists( 'MO' ) ): 13 14 class MO extends Gettext_Translations { 14 15 … … 96 97 97 98 function get_byteorder($magic) { 98 99 99 // The magic is 0x950412de 100 100 … … 103 103 $magic_little_64 = (int) 2500072158; 104 104 // 0xde120495 105 $magic_big = ((int) - 569244523) && 0xFFFFFFFF; 106 105 $magic_big = ((int) - 569244523) & 0xFFFFFFFF; 107 106 if ($magic_little == $magic || $magic_little_64 == $magic) { 108 107 return 'little'; … … 183 182 184 183 } 185 ?> 184 endif; -
trunk/wp-includes/pomo/po.php
r11626 r12079 3 3 * Class for working with PO files 4 4 * 5 * @version $Id: po.php 123 2009-05-13 19:35:43Z nbachiyski $5 * @version $Id: po.php 283 2009-09-23 16:21:51Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage po … … 17 17 * Routines for working with PO files 18 18 */ 19 if ( !class_exists( 'PO' ) ): 19 20 class PO extends Gettext_Translations { 20 21 … … 317 318 } 318 319 } 319 if (array() == array_filter($entry->translations)) $entry->translations = array(); 320 if (array() == array_filter($entry->translations, create_function('$t', 'return $t || "0" === $t;'))) { 321 $entry->translations = array(); 322 } 320 323 return array('entry' => $entry, 'lineno' => $lineno); 321 324 } … … 358 361 } 359 362 } 360 ?> 363 endif; -
trunk/wp-includes/pomo/streams.php
r11626 r12079 4 4 * Based on the classes from Danilo Segan <danilo@kvota.net> 5 5 * 6 * @version $Id: streams.php 138 2009-06-23 13:22:09Z nbachiyski $6 * @version $Id: streams.php 223 2009-09-07 21:20:13Z nbachiyski $ 7 7 * @package pomo 8 8 * @subpackage streams … … 10 10 11 11 12 if ( !class_exists( 'POMO_StringReader' ) ): 12 13 /** 13 14 * Provides file-like methods for manipulating a string instead … … 62 63 63 64 } 65 endif; 64 66 67 if ( !class_exists( 'POMO_CachedFileReader' ) ): 65 68 /** 66 69 * Reads the contents of the file in the beginning. … … 75 78 } 76 79 } 80 endif; 77 81 82 if ( !class_exists( 'POMO_CachedIntFileReader' ) ): 78 83 /** 79 84 * Allows reading integers from a file. … … 134 139 } 135 140 } 136 137 ?> 141 endif; -
trunk/wp-includes/pomo/translations.php
r11626 r12079 3 3 * Class for a set of entries for translation and their associated headers 4 4 * 5 * @version $Id: translations.php 114 2009-05-11 17:30:38Z nbachiyski $5 * @version $Id: translations.php 291 2009-10-21 05:46:08Z nbachiyski $ 6 6 * @package pomo 7 7 * @subpackage translations … … 10 10 require_once dirname(__FILE__) . '/entry.php'; 11 11 12 if ( !class_exists( 'Translations' ) ): 12 13 class Translations { 13 14 var $entries = array(); … … 26 27 $key = $entry->key(); 27 28 if (false === $key) return false; 28 $this->entries[$key] = $entry;29 $this->entries[$key] = &$entry; 29 30 return true; 30 31 } … … 118 119 function gettext_select_plural_form($count) { 119 120 if (!isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { 120 $plural_header = $this->get_header('Plural-Forms'); 121 $this->_gettext_select_plural_form = $this->_make_gettext_select_plural_form($plural_header); 121 list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); 122 $this->_nplurals = $nplurals; 123 $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); 122 124 } 123 125 return call_user_func($this->_gettext_select_plural_form, $count); 126 } 127 128 function nplurals_and_expression_from_header($header) { 129 if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { 130 $nplurals = (int)$matches[1]; 131 $expression = trim($this->parenthesize_plural_exression($matches[2])); 132 return array($nplurals, $expression); 133 } else { 134 return array(2, 'n != 1'); 135 } 124 136 } 125 137 … … 128 140 * plural forms header 129 141 */ 130 function _make_gettext_select_plural_form($plural_header) { 131 $res = create_function('$count', 'return 1 == $count? 0 : 1;'); 132 if ($plural_header && (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $plural_header, $matches))) { 133 $nplurals = (int)$matches[1]; 134 $this->_nplurals = $nplurals; 135 $plural_expr = trim($this->_parenthesize_plural_exression($matches[2])); 136 $plural_expr = str_replace('n', '$n', $plural_expr); 137 $func_body = " 138 \$index = (int)($plural_expr); 139 return (\$index < $nplurals)? \$index : $nplurals - 1;"; 140 $res = create_function('$n', $func_body); 141 } 142 return $res; 142 function make_plural_form_function($nplurals, $expression) { 143 $expression = str_replace('n', '$n', $expression); 144 $func_body = " 145 \$index = (int)($expression); 146 return (\$index < $nplurals)? \$index : $nplurals - 1;"; 147 return create_function('$n', $func_body); 143 148 } 144 149 … … 150 155 * @return string the expression with parentheses added 151 156 */ 152 function _parenthesize_plural_exression($expression) {157 function parenthesize_plural_exression($expression) { 153 158 $expression .= ';'; 154 159 $res = ''; … … 187 192 return $headers; 188 193 } 189 194 190 195 function set_header($header, $value) { 191 196 parent::set_header($header, $value); 192 if ('Plural-Forms' == $header) 193 $this->_gettext_select_plural_form = $this->_make_gettext_select_plural_form($value); 194 } 195 196 197 if ('Plural-Forms' == $header) { 198 list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); 199 $this->_nplurals = $nplurals; 200 $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); 201 } 202 } 197 203 } 198 199 ?> 204 endif; 205 206 if ( !class_exists( 'NOOP_Translations' ) ): 207 /** 208 * Provides the same interface as Translations, but doesn't do anything 209 */ 210 class NOOP_Translations { 211 var $entries = array(); 212 var $headers = array(); 213 214 function add_entry($entry) { 215 return true; 216 } 217 218 function set_header($header, $value) { 219 } 220 221 function set_headers(&$headers) { 222 } 223 224 function get_header($header) { 225 return false; 226 } 227 228 function translate_entry(&$entry) { 229 return false; 230 } 231 232 function translate($singular, $context=null) { 233 return $singular; 234 } 235 236 function select_plural_form($count) { 237 return 1 == $count? 0 : 1; 238 } 239 240 function get_plural_forms_count() { 241 return 2; 242 } 243 244 function translate_plural($singular, $plural, $count, $context = null) { 245 return 1 == $count? $singular : $plural; 246 } 247 248 function merge_with(&$other) { 249 } 250 } 251 endif;
Note: See TracChangeset
for help on using the changeset viewer.