Changeset 68 for trunk/WordPress/plugin/transposh/parser.php
- Timestamp:
- 03/17/2009 09:07:25 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/parser.php (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/parser.php
r61 r68 97 97 $tag_start = $pos; 98 98 $pos = strpos($page, '>', $pos); 99 99 100 100 //Mark tag end position 101 101 $tag_end = $pos; … … 156 156 logger("Exit " . __METHOD__, 4); 157 157 } 158 159 158 160 159 /* … … 209 208 global $is_in_channel; 210 209 $is_in_channel = TRUE; 211 break; 212 } 213 214 } 215 210 break; 211 } 212 213 } 216 214 217 215 /* … … 240 238 } 241 239 242 243 240 /* 244 241 * Process html tag. Set the direction for rtl languages. … … 301 298 if(is_word('![CDATA[')) 302 299 { 303 $pos += 8; //skip to end of ![CDATA[ 300 $pos += 8; //skip to end of ![CDATA[ 304 301 } 305 302 else … … 311 308 } 312 309 } 313 310 314 311 logger("Exit " . __METHOD__. ": $pos", 5); 315 312 return substr($page,$start, $pos - $start); … … 385 382 { 386 383 global $page, $pos; 387 384 388 385 logger("Enter " . __METHOD__ , 4); 389 386 … … 394 391 $start = $pos; 395 392 $page_length = strlen($page); 396 397 // Indicates if the html entity should break into a new translation segment. 398 $is_breaker = FALSE; 399 393 394 // Indicates if the html entity should break into a new translation segment. 395 $is_breaker = FALSE; 396 400 397 while($pos < $page_length && $page[$pos] != '<') 401 398 { … … 409 406 $start = $end_of_entity; 410 407 } 411 408 412 409 //skip past entity 413 410 $pos = $end_of_entity; … … 433 430 } 434 431 435 436 /* 437 * Translate the content of a cdata section. For now we only expect to handle it 438 * within RSS feeds. 432 /* 433 * Translate the content of a cdata section. For now we only expect to handle it 434 * within RSS feeds. 439 435 */ 440 436 function process_cdata_section() 441 437 { 442 438 global $page, $pos; 443 439 444 440 logger("Enter " . __METHOD__ , 4); 445 441 … … 450 446 $start = $pos; 451 447 $page_length = strlen($page); 452 448 453 449 while($pos < $page_length && !is_word(']]>')) 454 450 { … … 477 473 /** 478 474 * Determines position in page marks a transaltable tag in html page or rss feed section. 479 * Return TRUE if should be translated otherwise FALSE. 475 * Return TRUE if should be translated otherwise FALSE. 480 476 */ 481 477 function is_translatable_section() … … 484 480 $rc = FALSE; 485 481 $current_tag = end($tags_list); 486 482 487 483 if($is_in_body || $current_tag == 'title') 488 484 { … … 496 492 497 493 logger("Exit " . __METHOD__ . " $current_tag, translate: " . ($rc ? "yes" : "no"), 4); 498 return $rc; 494 return $rc; 499 495 } 500 496 … … 525 521 $page[$position] == ';' || 526 522 //break on numbers but not like: 3rd, 4th 527 (is_digit($position) && !is_a_to_z_character($position+1))) 523 (is_digit($position) && !is_a_to_z_character($position+1))) 528 524 { 529 525 //break the sentence into segments regardless of the next character. … … 537 533 * Determines if the current position marks the begining of an html 538 534 * entity. E.g & 539 * Return 0 if not an html entity otherwise return the position past this entity. In addition 535 * Return 0 if not an html entity otherwise return the position past this entity. In addition 540 536 * the $is_breaker will be set to TRUE if entity should break translation into a new segment. 541 537 * … … 677 673 } 678 674 679 680 675 /* 681 676 * Check within page buffer position for the given word. 682 677 * param word The word to look for. 683 * param index1 Optional position within the page buffer, if not available then the current 684 * position ($pos) is used. 678 * param index1 Optional position within the page buffer, if not available then the current 679 * position ($pos) is used. 685 680 * Return TRUE if the word matches otherwise FALSE 686 681 */ … … 689 684 global $page, $pos; 690 685 $rc = FALSE; 691 686 692 687 if(!isset($index1)) 693 688 { … … 695 690 $index1 = $pos; 696 691 } 697 692 698 693 $index2 = 0; //position within word 699 694 $word_len = strlen($word); 700 695 $page_length = strlen($page); 701 696 702 697 while($index1 < $page_length && $index2 < $word_len) 703 698 { … … 712 707 } 713 708 } 714 709 715 710 //check if we have full match 716 711 if($index2 == $word_len) … … 718 713 $rc = TRUE; 719 714 } 720 715 721 716 return $rc; 722 717 } 723 718 724 725 /** 719 /* 726 720 * Translate the text between the given start position and the current 727 721 * position (pos) within the buffer. … … 757 751 } 758 752 759 $translated_text= fetch_translation($original_text);760 761 insert_translation($original_text, $translated_text, $s tart, $end);753 list($translated_text, $source) = fetch_translation($original_text); 754 755 insert_translation($original_text, $translated_text, $source, $start, $end); 762 756 } 763 757 … … 769 763 * param end Marks the end position of the text to be replaced within the original page 770 764 */ 771 function insert_translation(&$original_text, &$translated_text, $s tart, $end)765 function insert_translation(&$original_text, &$translated_text, $source, $start, $end) 772 766 { 773 767 global $segment_id, $is_edit_mode, $tags_list; … … 784 778 else 785 779 { 786 $span = "<span id=\"" . SPAN_PREFIX . "$segment_id\">"; 780 $span_prefix = SPAN_PREFIX; 781 // We will mark translated text with tr_t class and untranslated with tr_u 782 $span = "<span class=\"$span_prefix"; 787 783 788 784 if($translated_text == NULL) 789 785 { 786 $span .= "u\" id=\"{$span_prefix}{$segment_id}\">"; 790 787 $span .= $original_text . '</span>'; 791 788 } 792 789 else 793 790 { 791 $span .= "t\" id=\"{$span_prefix}{$segment_id}\">"; 794 792 $span .= $translated_text . "</span>"; 795 793 $is_translated = TRUE; … … 801 799 802 800 //Insert image to allow editing this segment 803 $img = get_img_tag($original_text, $translated_text, $s egment_id, $is_translated);801 $img = get_img_tag($original_text, $translated_text, $source, $segment_id, $is_translated); 804 802 update_translated_page($end + 1, - 1, $img); 805 803 … … 813 811 } 814 812 815 816 813 /* 817 814 * Scrubs text prior to translation to remove/encode special … … 833 830 return $text; 834 831 } 835 836 832 837 833 /** … … 865 861 866 862 } 867 868 863 ?>
Note: See TracChangeset
for help on using the changeset viewer.
