Changeset 518


Ignore:
Timestamp:
08/26/2010 01:50:50 AM (18 months ago)
Author:
ofer
Message:

Parser support for inner text markings, # and * are now handled as numbers

Location:
trunk/WordPress/plugin/transposh/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/constants.php

    r504 r518  
    2727define('NO_TRANSLATE_CLASS_GOOGLE', 'notranslate'); 
    2828define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage'); 
     29 
     30//Get text breakers 
     31define('TP_GETTEXT_BREAKER', chr(1)); 
     32define('TP_GETTEXT_INNER_BREAKER', chr(2)); 
    2933 
    3034/** 
  • trunk/WordPress/plugin/transposh/core/parser.php

    r515 r518  
    114114    /** @var parserstats Contains parsing statistics */ 
    115115    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; 
    116120 
    117121    /** 
     
    274278     */ 
    275279    function is_number($page, $position) { 
    276         return strspn($page, '0123456789-+$%,.\\/', $position); 
     280        return strspn($page, '0123456789-+$%#*,.\\/', $position); 
    277281    } 
    278282 
     
    282286     * @param int $end - end of phrase in element 
    283287     */ 
    284     function tag_phrase($string, $start, $end, $gettext = false) { 
     288    function tag_phrase($string, $start, $end) { 
    285289        $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        } 
    286294        if ($phrase) { 
    287295            logger($phrase, 4); 
     
    296304            if ($this->inbody) $node->inbody = $this->inbody; 
    297305            if ($this->inselect) $node->inselect = true; 
    298             if ($gettext) { 
    299                 $node->phrase = substr(substr($phrase, 11), 0, -11); 
    300                 $node->gettext = true; 
    301             } 
    302306        } 
    303307    } 
     
    325329                $entity = substr($string, $pos, $len_of_entity); 
    326330                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); 
    328332                    $this->tag_phrase($string, $start, $pos); 
    329333                    $start = $pos + $len_of_entity; 
    330                 } 
    331                 //goaway entity 
    332                 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                     } 
    341334                } 
    342335                //skip past entity 
     
    350343                $pos++; 
    351344                $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; 
    352360            } 
    353361            // will break translation unit when there's a breaker ",.[]()..." 
     
    749757                $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>"; 
    750758 
     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); 
    751761        // Changed because of places where tostring failed 
    752762        //return $this->html; 
    753         return $this->html->outertext; 
     763        //return $this->html->outertext; 
    754764    } 
    755765 
     
    775785 
    776786} 
     787 
    777788?> 
Note: See TracChangeset for help on using the changeset viewer.