Changeset 518
- Timestamp:
- 08/26/2010 01:50:50 AM (18 months ago)
- Location:
- trunk/WordPress/plugin/transposh/core
- Files:
-
- 2 edited
-
constants.php (modified) (1 diff)
-
parser.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/constants.php
r504 r518 27 27 define('NO_TRANSLATE_CLASS_GOOGLE', 'notranslate'); 28 28 define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage'); 29 30 //Get text breakers 31 define('TP_GETTEXT_BREAKER', chr(1)); 32 define('TP_GETTEXT_INNER_BREAKER', chr(2)); 29 33 30 34 /** -
trunk/WordPress/plugin/transposh/core/parser.php
r515 r518 114 114 /** @var parserstats Contains parsing statistics */ 115 115 private $stats; 116 /** @var boolean Are we inside a translated gettext */ 117 private $in_get_text = false; 118 /** @var boolean Are we inside an inner text %s in gettext */ 119 private $in_get_text_inner = false; 116 120 117 121 /** … … 274 278 */ 275 279 function is_number($page, $position) { 276 return strspn($page, '0123456789-+$% ,.\\/', $position);280 return strspn($page, '0123456789-+$%#*,.\\/', $position); 277 281 } 278 282 … … 282 286 * @param int $end - end of phrase in element 283 287 */ 284 function tag_phrase($string, $start, $end , $gettext = false) {288 function tag_phrase($string, $start, $end) { 285 289 $phrase = trim(substr($string, $start, $end - $start)); 290 if ($this->in_get_text && !$this->in_get_text_inner) { 291 logger('not tagging ' . $phrase . ' assumed gettext translated', 4); 292 return; 293 } 286 294 if ($phrase) { 287 295 logger($phrase, 4); … … 296 304 if ($this->inbody) $node->inbody = $this->inbody; 297 305 if ($this->inselect) $node->inselect = true; 298 if ($gettext) {299 $node->phrase = substr(substr($phrase, 11), 0, -11);300 $node->gettext = true;301 }302 306 } 303 307 } … … 325 329 $entity = substr($string, $pos, $len_of_entity); 326 330 if (($this->is_white_space($string[$pos + $len_of_entity]) || $this->is_entity_breaker($entity)) && !$this->is_entity_letter($entity)) { 327 logger("entity ($entity) breaks", 5);331 logger("entity ($entity) breaks", 3); 328 332 $this->tag_phrase($string, $start, $pos); 329 333 $start = $pos + $len_of_entity; 330 }331 //goaway entity332 if ($entity == '&transposh;') {333 $closerent = strpos($string, $entity, $start);334 if ($closerent !== false) {335 $start = $pos;336 $this->tag_phrase($string, $start, $closerent + $len_of_entity, true); //special tagging?337 $start = $closerent + $len_of_entity;338 $pos = $closerent;339 logger("Process of transposh entity $pos $string $closerent");340 }341 334 } 342 335 //skip past entity … … 350 343 $pos++; 351 344 $start = $pos; 345 } elseif ($string[$pos] == TP_GETTEXT_BREAKER) { 346 logger("text breaker $start $pos $string " . (($this->in_get_text) ? 'true' : 'false'), 5); 347 $this->tag_phrase($string, $start, $pos); 348 $pos++; 349 $start = $pos; 350 $this->in_get_text = !$this->in_get_text; // flipping state 351 if ($pos == 1) 352 $this->in_get_text = true; // reset state based on string start 353 $this->in_get_text_inner = false; 354 } elseif ($string[$pos] == TP_GETTEXT_INNER_BREAKER) { 355 logger("inner text breaker $start $pos $string " . (($this->in_get_text_inner) ? 'true' : 'false'), 5); 356 $this->tag_phrase($string, $start, $pos); 357 $pos++; 358 $start = $pos; 359 $this->in_get_text_inner = !$this->in_get_text_inner; 352 360 } 353 361 // will break translation unit when there's a breaker ",.[]()..." … … 749 757 $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>"; 750 758 759 // we make sure that the result is clear from our shananigans 760 return str_replace(array(TP_GETTEXT_BREAKER, TP_GETTEXT_INNER_BREAKER), '', $this->html->outertext); 751 761 // Changed because of places where tostring failed 752 762 //return $this->html; 753 return $this->html->outertext;763 //return $this->html->outertext; 754 764 } 755 765 … … 775 785 776 786 } 787 777 788 ?>
Note: See TracChangeset
for help on using the changeset viewer.
