Ignore:
Timestamp:
03/19/2009 12:22:25 PM (3 years ago)
Author:
amir
Message:

Fixed parsing of nubmers which should be excluded from translation unless they are in this form 1st 18th ... .
Exclude js includes when not needed.
Some minor cosmetics changes as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/parser.php

    r74 r76  
    5656//Is current position within the channel tag, i.e. RSS feed 
    5757$is_in_channel = FALSE; 
     58 
     59//Indicates whether automatic translation (i.e. google) is enabled for this page 
     60$enable_auto_translate; 
    5861 
    5962/* 
     
    416419                                $start = $pos; 
    417420                        } 
     421                        else if($end_of_number = is_number($pos)) 
     422                        { 
     423                                //numbers will break translations segements and will not be included in the translation 
     424                                translate_text($start); 
     425                                $pos = $start = $end_of_number; 
     426                        }                        
    418427                        else 
    419428                        { 
     
    456465                                $pos++; 
    457466                                $start = $pos; 
     467                        } 
     468                        else if($end_of_number = is_number($pos)) 
     469                        { 
     470                                //numbers will break translations segements and will not be included in the translation 
     471                                translate_text($start); 
     472                                $pos = $start = $end_of_number; 
    458473                        } 
    459474                        else 
     
    519534                        $page[$position] == '"' || $page[$position] == '!' || 
    520535                        $page[$position] == ':' || $page[$position] == '|' || 
    521                         $page[$position] == ';' || 
    522                         //break on numbers but not like: 3rd, 4th 
    523                         (is_digit($position) && !is_a_to_z_character($position+1))) 
     536                        $page[$position] == ';') 
    524537        { 
    525538                //break the sentence into segments regardless of the next character. 
     
    570583} 
    571584 
     585/* 
     586 * Determines if the current position marks the begining of a number, e.g. 123 050-391212232 
     587 *  
     588 * Return 0 if not a number otherwise return the position past this number.  
     589 */ 
     590function is_number($position) 
     591{ 
     592        global $page; 
     593        $start = $position; 
     594         
     595        while(is_digit($position) || $page[$position] == '-' || $page[$position] == '+') 
     596        { 
     597                $position++; 
     598        } 
     599         
     600        if($position != $start && (is_white_space($position) || $page[$position] == '<')) 
     601        { 
     602                return $position;                
     603        } 
     604         
     605        return 0; 
     606} 
    572607 
    573608/* 
     
    622657                return TRUE; 
    623658        } 
    624 } 
    625  
    626 /* 
    627  * Skip within buffer past unreadable characters , i.e. white space 
    628  * and characters considred to be a sentence breaker. Staring from the specified 
    629  * position going either forward or backward. 
    630  * param forward - indicate direction going either backward of forward. 
    631  */ 
    632 function skip_unreadable_chars(&$index, $forward=TRUE) 
    633 { 
    634         global $page, $pos; 
    635  
    636         if(!isset($index)) 
    637         { 
    638                 //use $pos as the default position if not specified otherwise 
    639                 $index = &$pos; 
    640         } 
    641         $start = $index; 
    642  
    643         while($index < strlen($page) && $index > 0 && 
    644         (is_white_space($index) || is_sentence_breaker($index))) 
    645         { 
    646                 ($forward ? $index++ : $index--); 
    647         } 
    648  
    649         return $index; 
    650659} 
    651660 
     
    769778        $is_translated = FALSE; 
    770779 
    771         if(!($is_edit_mode || get_option(ENABLE_AUTO_TRANSLATE,1)) || !in_array('body', $tags_list)) 
     780        if(!($is_edit_mode || $enable_auto_translate) || !in_array('body', $tags_list)) 
    772781        { 
    773782                if($translated_text != NULL) 
Note: See TracChangeset for help on using the changeset viewer.