Development

Changeset 8453

You must first sign up to be able to contribute.

Changeset 8453

Show
Ignore:
Timestamp:
04/14/08 18:39:14 (2 years ago)
Author:
fabien
Message:

added logic to i18n:find to also find strings in PHP code (closes #3320)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/task/i18n/sfI18nFindTask.class.php

    r8452 r8453  
    4141  [./symfony i18n:find frontend|INFO] 
    4242 
    43 This task has a very limited understanding of templates and can only find simple strings like this one: 
     43This task is able to find non internationalized strings in pure HTML and in PHP code: 
    4444 
    4545  <p>Non i18n text</p> 
     46  <p><?php echo 'Test' ?></p> 
    4647 
    47 But it can't find strings embedded in PHP code like this one: 
    48  
    49   <p><?php echo 'Test' ?></p> 
     48As the task returns all strings embedded in PHP, you can have some false positive (especially 
     49if you use the string syntax for helper arguments). 
    5050EOF; 
    5151  } 
     
    7373      foreach ($templates as $template) 
    7474      { 
     75        if (!isset($strings[$template])) 
     76        { 
     77          $strings[$template] = array(); 
     78        } 
     79 
    7580        $dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8')); 
    7681        $content = file_get_contents($template); 
     
    9095            if (!$node->isWhitespaceInElementContent()) 
    9196            { 
    92               if (!isset($strings[$template])) 
    93               { 
    94                 $strings[$template] = array(); 
    95               } 
    96  
    9797              $strings[$template][] = $node->nodeValue; 
    9898            } 
     
    105105            } 
    106106          } 
     107          else if ('DOMProcessingInstruction' == get_class($node) && 'php' == $node->target) 
     108          { 
     109            // processing instruction node 
     110            $tokens = token_get_all('<?php '.$node->nodeValue); 
     111            foreach ($tokens as $token) 
     112            { 
     113              if (is_array($token)) 
     114              { 
     115                list($id, $text) = $token; 
     116 
     117                if (T_CONSTANT_ENCAPSED_STRING === $id) 
     118                { 
     119                  $strings[$template][] = substr($text, 1, -1); 
     120                } 
     121              } 
     122            } 
     123          } 
    107124        } 
    108125      } 
     
    111128    foreach ($strings as $template => $messages) 
    112129    { 
     130      if (!$messages) 
     131      { 
     132        continue; 
     133      } 
     134 
    113135      $this->logSection('i18n', sprintf('strings in "%s"', str_replace(sfConfig::get('sf_root_dir'), '', $template)), 1000); 
    114136      foreach ($messages as $message) 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.