Changeset 633 for trunk


Ignore:
Timestamp:
06/02/2011 02:40:27 AM (12 months ago)
Author:
ofer
Message:

Allow users to fiddle with source to change parser behaviours with more ease than in the past.

File:
1 edited

Legend:

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

    r632 r633  
    1616require_once("logging.php"); 
    1717require_once("utils.php"); 
     18 
     19define('PUNCT_BREAKS', TRUE); // Will punctiations such as , . ( and such will break a phrase 
     20define('NUM_BREAKS', TRUE); // Will a number break a phrase 
     21define('ENT_BREAKS', TRUE); // Will an HTML entity break a phrase 
    1822 
    1923/** 
     
    341345        while ($pos < strlen($string)) { 
    342346            // Some HTML entities make us break, almost all but apostrophies 
    343             if ($len_of_entity = $this->is_html_entity($string, $pos)) { 
     347            if (ENT_BREAKS && $len_of_entity = $this->is_html_entity($string, $pos)) { 
    344348                $entity = substr($string, $pos, $len_of_entity); 
    345349                if (($this->is_white_space(@$string[$pos + $len_of_entity]) || $this->is_entity_breaker($entity)) && !$this->is_entity_letter($entity)) { 
     
    382386            } 
    383387            // will break translation unit when there's a breaker ",.[]()..." 
    384             elseif ($senb_len = $this->is_sentence_breaker($string[$pos], @$string[$pos + 1], @$string[$pos + 2])) { 
     388            elseif (PUNCT_BREAKS && $senb_len = $this->is_sentence_breaker($string[$pos], @$string[$pos + 1], @$string[$pos + 2])) { 
    385389//                logger ("sentence breaker..."); 
    386390                $this->tag_phrase($string, $start, $pos); 
     
    390394            // Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too... 
    391395            // also prefixed by whitespace? 
    392             elseif ($num_len = $this->is_number($string, $pos)) { 
     396            elseif (NUM_BREAKS && $num_len = $this->is_number($string, $pos)) { 
    393397//                logger ("numnum... $num_len"); 
    394398                // this is the case of B2 or B2, 
     
    695699        //fix urls more 
    696700        // WORK IN PROGRESS 
    697         /*foreach ($this->atags as $e) { 
    698             $hrefspans = ''; 
    699             foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) { 
    700                 // fix - not for dashes 
    701                 list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($part, $this->lang)); 
    702                 $hrefspans .= $this->create_edit_span($part, $translated_text, $source, true); 
    703             } 
     701        /* foreach ($this->atags as $e) { 
     702          $hrefspans = ''; 
     703          foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) { 
     704          // fix - not for dashes 
     705          list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($part, $this->lang)); 
     706          $hrefspans .= $this->create_edit_span($part, $translated_text, $source, true); 
     707          } 
     708          $e->href = call_user_func_array($this->url_rewrite_func, array($e->href)); 
     709          $e->outertext .= $hrefspans; 
     710          } */ 
     711 
     712        // fix urls... 
     713        foreach ($this->atags as $e) { 
    704714            $e->href = call_user_func_array($this->url_rewrite_func, array($e->href)); 
    705             $e->outertext .= $hrefspans; 
    706         }*/ 
    707  
    708         // fix urls... 
    709              foreach ($this->atags as $e) { 
    710               $e->href = call_user_func_array($this->url_rewrite_func, array($e->href)); 
    711715        } 
    712716        foreach ($this->otags as $e) { 
Note: See TracChangeset for help on using the changeset viewer.