Changeset 522 for trunk/WordPress/plugin/transposh/core/parser.php
- Timestamp:
- 08/27/2010 02:26:28 PM (21 months ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/core/parser.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/parser.php
r518 r522 270 270 //· 271 271 if (ord($char) == 194 && ord($nextchar) == 183) return 2; 272 return (strpos(',?()[]"!:|;' , $char) !== false) ? 1 : 0; // TODO: might need to add < and > here272 return (strpos(',?()[]"!:|;'.TP_GETTEXT_BREAKER.TP_GETTEXT_CLOSER.TP_GETTEXT_INNER_BREAKER.TP_GETTEXT_INNER_BREAKER_CLOSER, $char) !== false) ? 1 : 0; // TODO: might need to add < and > here 273 273 } 274 274 … … 288 288 function tag_phrase($string, $start, $end) { 289 289 $phrase = trim(substr($string, $start, $end - $start)); 290 if ($this->in_get_text && !$this->in_get_text_inner) { 290 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 291 // logger ("p:$phrase, s:$logstr, st:$start, en:$end, gt:{$this->in_get_text}, gti:{$this->in_get_text_inner}"); 292 // logger (''); 293 if ($this->in_get_text > $this->in_get_text_inner) { 291 294 logger('not tagging ' . $phrase . ' assumed gettext translated', 4); 292 295 return; … … 343 346 $pos++; 344 347 $start = $pos; 345 } elseif ($string[$pos] == TP_GETTEXT_BREAKER) { 346 logger("text breaker $start $pos $string " . (($this->in_get_text) ? 'true' : 'false'), 5); 348 } elseif ($string[$pos] == TP_GTXT_BRK || $string[$pos] == TP_GTXT_BRK_CLOSER) { 349 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 350 // $closers = ($string[$pos] == TP_GTXT_BRK) ? '': 'closer'; 351 // logger(" $closers TEXT breaker $logstr start:$start pos:$pos gt:" . $this->in_get_text, 3); 347 352 $this->tag_phrase($string, $start, $pos); 353 ($string[$pos] == TP_GTXT_BRK) ? $this->in_get_text += 1: $this->in_get_text -= 1; 348 354 $pos++; 349 355 $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 // reset state based on string start, no need to flip 357 //$this->in_get_text = ($pos == 1); 358 //if (!$this->in_get_text) $this->in_get_text_inner = false; 359 } elseif ($string[$pos] == TP_GTXT_IBRK || $string[$pos] == TP_GTXT_IBRK_CLOSER ) { 360 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 361 // $closers = ($string[$pos] == TP_GTXT_IBRK) ? '': 'closer'; 362 // logger(" $closers INNER text breaker $logstr start:$start pos:$pos gt:" . $this->in_get_text_inner, 3); 363 //logger("inner text breaker $start $pos $string " . (($this->in_get_text_inner) ? 'true' : 'false'), 5); 356 364 $this->tag_phrase($string, $start, $pos); 365 if ($this->in_get_text) 366 ($string[$pos] == TP_GTXT_IBRK) ? $this->in_get_text_inner += 1 : $this->in_get_text_inner -=1; 357 367 $pos++; 358 368 $start = $pos; 359 $this->in_get_text_inner = !$this->in_get_text_inner;369 //$this->in_get_text_inner = !$this->in_get_text_inner; 360 370 } 361 371 // will break translation unit when there's a breaker ",.[]()..." 362 372 elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) { 373 // logger ("sentence breaker..."); 363 374 $this->tag_phrase($string, $start, $pos); 364 375 $pos += $senb_len; … … 368 379 // also prefixed by whitespace? 369 380 elseif ($num_len = $this->is_number($string, $pos)) { 381 // logger ("numnum... $num_len"); 370 382 // this is the case of B2 or B2, 371 383 if (($this->is_white_space($string[$pos - 1]) || ($start == $pos) … … 373 385 ($this->is_white_space($string[$pos + $num_len]) || $this->is_sentence_breaker($string[$pos + $num_len], $string[$pos + $num_len + 1], $string[$pos + $num_len + 2]))) { 374 386 // we will now compensate on the number followed by breaker case, if we need to 387 // logger ("compensate part1?"); 375 388 if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) { 389 // logger ("compensate part2?"); 376 390 if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) { 391 // logger ("compensate 3?"); 377 392 $num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate 378 393 } … … 381 396 } 382 397 $this->tag_phrase($string, $start, $pos); 383 $start = $pos + $num_len + 1; 384 } 385 $pos += $num_len + 1; 398 $start = $pos + $num_len /*+1*/; 399 } 400 $pos += $num_len/* + 1*/; 401 // logger ("numnumpos... $pos"); 386 402 } else { 387 403 // smarter marking of start location … … 557 573 $this->html = str_get_html($string); 558 574 // mark translateable elements 575 $this->html->find('html', 0)->lang = ''; // Document defined lang may be preset to correct lang, but should be ignored TODO: Better? 559 576 $this->translate_tagging($this->html->root); 560 577 … … 758 775 759 776 // we make sure that the result is clear from our shananigans 760 return str_replace(array(TP_G ETTEXT_BREAKER, TP_GETTEXT_INNER_BREAKER), '', $this->html->outertext);777 return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext); 761 778 // Changed because of places where tostring failed 762 779 //return $this->html;
Note: See TracChangeset
for help on using the changeset viewer.
