Changeset 581


Ignore:
Timestamp:
01/06/2011 03:23:20 AM (17 months ago)
Author:
ofer
Message:

Allow meta translation (#96), and also fixed what previously broken with selects, now metas and hidden elements out of body tags are put to the bottom of the page

File:
1 edited

Legend:

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

    r577 r581  
    507507        if ($node->title) $this->parsetext($node->title); 
    508508 
    509         // Meta content (keywords, description) are also good places to translate 
    510         if ($node->tag == 'meta' && $node->content) 
     509        // Meta content (keywords, description) are also good places to translate (but not in robots...) 
     510        if ($node->tag == 'meta' && $node->content && ($node->name != 'robots')) 
    511511                $this->parsetext($node->content); 
    512512 
     
    671671        } 
    672672 
     673        // this is used to reserve spans we cannot add directly (out of body, metas, etc) 
     674        $hiddenspans = ''; 
     675        $savedspan = ''; 
     676 
    673677        // actually translate tags 
    674678        // texts are first 
    675679        foreach ($this->html->find('text') as $e) { 
    676680            $replace = array(); 
    677             $savedspan = ''; 
    678681            foreach ($e->nodes as $ep) { 
    679682                list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang)); 
     
    685688                } 
    686689                if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody */) { 
    687                     if ($ep->inselect || !$ep->inbody) { 
     690                    if ($ep->inselect) { 
    688691                        $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang); 
     692                    } elseif (!$ep->inbody) { 
     693                        $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang); 
    689694                    } else { 
    690695                        $translated_text = $this->create_edit_span($ep->phrase, $translated_text, $source, false, $ep->srclang); 
     
    765770        } 
    766771 
    767         // now we handle the meta content - which is simpler because they can't be edited or auto-translated 
     772        // now we handle the meta content - which is simpler because they can't be edited or auto-translated in place 
    768773        // we also don't expect any father modifications here 
     774        // so we now add all those spans right before the <body> tag end 
    769775        foreach ($this->html->find('[content]') as $e) { 
    770776            $right = ''; 
     
    786792                        $e->content = $right; 
    787793                    } 
     794                    if ($this->is_edit_mode) { 
     795                            $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang); 
     796                    } 
     797                    if (!$translated_text && $this->is_auto_translate && !$this->is_edit_mode) { 
     798                        logger('untranslated meta for ' . $ep->phrase . ' ' . $this->lang); 
     799                        if ($this->is_edit_mode || $this->is_auto_translate) { // FIX 
     800                        } 
     801                    } 
    788802                } 
    789803            } 
     
    792806                logger("content-phrase: $newtext", 4); 
    793807            } 
     808        } 
     809 
     810        if ($hiddenspans) { 
     811            $body = $this->html->find('body', 0); 
     812            if ($body != null) $body->lastChild()->outertext .= $hiddenspans; 
    794813        } 
    795814        // only in 5 out of 100 pages, with just translated pages, we might show an ad for transposh 
Note: See TracChangeset for help on using the changeset viewer.