Ignore:
Timestamp:
08/27/2010 02:26:28 PM (21 months ago)
Author:
ofer
Message:

Provide a working gettext interface that blends with Transposh

File:
1 edited

Legend:

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

    r518 r522  
    270270        //· 
    271271        if (ord($char) == 194 && ord($nextchar) == 183) return 2; 
    272         return (strpos(',?()[]"!:|;', $char) !== false) ? 1 : 0; // TODO: might need to add < and > here 
     272        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 
    273273    } 
    274274 
     
    288288    function tag_phrase($string, $start, $end) { 
    289289        $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) { 
    291294            logger('not tagging ' . $phrase . ' assumed gettext translated', 4); 
    292295            return; 
     
    343346                $pos++; 
    344347                $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); 
    347352                $this->tag_phrase($string, $start, $pos); 
     353                ($string[$pos] == TP_GTXT_BRK) ? $this->in_get_text += 1: $this->in_get_text -= 1; 
    348354                $pos++; 
    349355                $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); 
    356364                $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; 
    357367                $pos++; 
    358368                $start = $pos; 
    359                 $this->in_get_text_inner = !$this->in_get_text_inner; 
     369                //$this->in_get_text_inner = !$this->in_get_text_inner; 
    360370            } 
    361371            // will break translation unit when there's a breaker ",.[]()..." 
    362372            elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) { 
     373//                logger ("sentence breaker..."); 
    363374                $this->tag_phrase($string, $start, $pos); 
    364375                $pos += $senb_len; 
     
    368379            // also prefixed by whitespace? 
    369380            elseif ($num_len = $this->is_number($string, $pos)) { 
     381//                logger ("numnum... $num_len"); 
    370382                // this is the case of B2 or B2, 
    371383                if (($this->is_white_space($string[$pos - 1]) || ($start == $pos) 
     
    373385                        ($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]))) { 
    374386                    // we will now compensate on the number followed by breaker case, if we need to 
     387//                            logger ("compensate part1?"); 
    375388                    if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) { 
     389//                            logger ("compensate part2?"); 
    376390                        if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) { 
     391//                            logger ("compensate 3?"); 
    377392                            $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 
    378393                        } 
     
    381396                    } 
    382397                    $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"); 
    386402            } else { 
    387403                // smarter marking of start location 
     
    557573        $this->html = str_get_html($string); 
    558574        // 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? 
    559576        $this->translate_tagging($this->html->root); 
    560577 
     
    758775 
    759776        // 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); 
     777        return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext); 
    761778        // Changed because of places where tostring failed 
    762779        //return $this->html; 
Note: See TracChangeset for help on using the changeset viewer.