Changeset 151


Ignore:
Timestamp:
04/07/2009 12:08:58 AM (3 years ago)
Author:
ofer
Message:

Collecting stats, not doing anything useful with it

File:
1 edited

Legend:

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

    r142 r151  
    3535$pos = 0; 
    3636 
     37//Used for statistics 
     38$phrase_count = 0; 
     39$pharses_by_human = 0; 
     40$pharses_by_cat = 0; 
     41 
    3742//Contains the stack of tag in the current position within the page 
    3843$tags_list = array(); 
     
    6166        logger("Enter " . __METHOD__, 4); 
    6267 
    63         global $page, $tr_page, $pos, $tags_list, $lang; 
     68        global $page, $tr_page, $pos, $tags_list, $lang, $phrase_count, $pharses_by_human, $pharses_by_cat; 
    6469        $no_translate = 0; 
    6570        $page_length = strlen($page); 
     
    150155        } 
    151156 
     157        logger("Stats: all-$phrase_count, cat-$pharses_by_cat, human-$pharses_by_human", 0); 
    152158        logger("Exit " . __METHOD__, 4); 
    153159} 
     
    453459                        //will break translation unit when one of the following characters is reached: ., 
    454460                        if(is_sentence_breaker($pos) || 
    455                            $page[$pos] == '<' || $page[$pos] == '>')  //only in cdata the < > are valid breakers as well 
     461                        $page[$pos] == '<' || $page[$pos] == '>')  //only in cdata the < > are valid breakers as well 
    456462                        { 
    457463                                translate_text($start); 
     
    498504        } 
    499505        else if($is_in_channel && 
    500                 ($current_tag == 'title' || $current_tag == 'description' || $current_tag == 'category')) 
     506        ($current_tag == 'title' || $current_tag == 'description' || $current_tag == 'category')) 
    501507        { 
    502508                $rc = TRUE; 
     
    527533        } 
    528534        else if($page[$position] == ',' || $page[$position] == '?' || 
    529                     $page[$position] == '(' || $page[$position] == ')' || 
    530                     $page[$position] == '[' || $page[$position] == ']' || 
    531                         $page[$position] == '"' || $page[$position] == '!' || 
    532                         $page[$position] == ':' || $page[$position] == '|' || 
    533                         $page[$position] == ';') 
     535        $page[$position] == '(' || $page[$position] == ')' || 
     536        $page[$position] == '[' || $page[$position] == ']' || 
     537        $page[$position] == '"' || $page[$position] == '!' || 
     538        $page[$position] == ':' || $page[$position] == '|' || 
     539        $page[$position] == ';') 
    534540        { 
    535541                //break the sentence into segments regardless of the next character. 
     
    569575                        //Exception: don't break when we there is a white space after the apostrophe. e.g. `uncategorized` 
    570576                        if(($entity ==  "&#8217;" || $entity == "&apos;" || $entity == "&#039;") 
    571                             && $page[$end_pos + 1] != " ") 
     577                        && $page[$end_pos + 1] != " ") 
    572578                        { 
    573579                                $is_breaker = FALSE; 
     
    598604 
    599605        while(is_digit($position) || $page[$position] == '-' || $page[$position] == '+' || 
    600          (($page[$position] == ',' || $page[$position] == '.' || $page[$position] == '\\' || $page[$position] == '/') && is_digit($position+1))) 
     606        (($page[$position] == ',' || $page[$position] == '.' || $page[$position] == '\\' || $page[$position] == '/') && is_digit($position+1))) 
    601607        { 
    602608                $position++; 
     
    738744{ 
    739745        logger("Enter " . __METHOD__  . " : $start", 4); 
    740         global $page, $pos, $lang; 
     746        global $page, $pos, $lang, $phrase_count, $pharses_by_human, $pharses_by_cat; 
    741747 
    742748        //trim white space from the start position going forward 
     
    767773        list($translated_text, $source) = fetch_translation($original_text, $lang); 
    768774 
     775        $phrase_count++; 
     776        if ($translated_text != NULL) { 
     777                if ($source) { 
     778                        $pharses_by_cat++; 
     779                } else  { 
     780                        $pharses_by_human++; 
     781                } 
     782        } 
     783 
    769784        insert_translation($original_text, $translated_text, $source, $start, $end); 
    770785} 
     
    790805 
    791806                //Use base64 encoding to make that when the page is translated (i.e. update_translation) we 
    792         //get back exactlly the same string without having the client decode/encode it in anyway. 
    793         $token = "token=\"" . base64_url_encode($original_text) . "\""; 
    794  
    795         if($translated_text == NULL) 
    796                 { 
    797                     $span .= "u\" id=\"{$span_prefix}{$segment_id}\" $token>"; 
     807                //get back exactlly the same string without having the client decode/encode it in anyway. 
     808                $token = "token=\"" . base64_url_encode($original_text) . "\""; 
     809 
     810                if($translated_text == NULL) 
     811                { 
     812                        $span .= "u\" id=\"{$span_prefix}{$segment_id}\" $token>"; 
    798813                        $span .= $original_text . '</span>'; 
    799814                } 
     
    907922        //Allow specific override for url rewriting . 
    908923        if($enable_permalinks_rewrite &&  function_exists('is_url_excluded_from_permalink_rewrite') && 
    909            is_url_excluded_from_permalink_rewrite($href)) 
     924        is_url_excluded_from_permalink_rewrite($href)) 
    910925        { 
    911926                $use_params = TRUE; 
Note: See TracChangeset for help on using the changeset viewer.