Development

Changeset 8452

You must first sign up to be able to contribute.

Changeset 8452

Show
Ignore:
Timestamp:
04/14/08 17:28:10 (5 months ago)
Author:
fabien
Message:

added help message to i18n:find + added layouts as templates to look for i18n strings

Files:

Legend:

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

    r8148 r8452  
    3737 
    3838    $this->detailedDescription = <<<EOF 
     39The [i18n:find|INFO] task finds non internationalized strings embedded in templates: 
     40 
     41  [./symfony i18n:find frontend|INFO] 
     42 
     43This task has a very limited understanding of templates and can only find simple strings like this one: 
     44 
     45  <p>Non i18n text</p> 
     46 
     47But it can't find strings embedded in PHP code like this one: 
     48 
     49  <p><?php echo 'Test' ?></p> 
    3950EOF; 
    4051  } 
     
    4859 
    4960    // Look in templates 
     61    $dirs = array(); 
    5062    $moduleNames = sfFinder::type('dir')->maxdepth(0)->relative()->in(sfConfig::get('sf_app_module_dir')); 
    51     $strings = array(); 
    5263    foreach ($moduleNames as $moduleName) 
    5364    { 
    54       $dir = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/templates'; 
    55       $templates = sfFinder::type('file')->name('*.php')->relative()->in($dir); 
     65      $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/templates'; 
     66    } 
     67    $dirs[] = sfConfig::get('sf_app_dir').'/templates'; 
     68 
     69    $strings = array(); 
     70    foreach ($dirs as $dir) 
     71    { 
     72      $templates = sfFinder::type('file')->name('*.php')->in($dir); 
    5673      foreach ($templates as $template) 
    5774      { 
    5875        $dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8')); 
    59         @$dom->loadXML('<doc>'.file_get_contents($dir.'/'.$template).'</doc>'); 
     76        $content = file_get_contents($template); 
     77 
     78        // remove doctype 
     79        $content = preg_replace('/<!DOCTYPE.*?>/', '', $content); 
     80 
     81        @$dom->loadXML('<doc>'.$content.'</doc>'); 
    6082 
    6183        $nodes = array($dom); 
     
    6890            if (!$node->isWhitespaceInElementContent()) 
    6991            { 
    70               if (!isset($strings[$moduleName][$template])) 
     92              if (!isset($strings[$template])) 
    7193              { 
    72                 if (!isset($strings[$moduleName])) 
    73                 { 
    74                   $strings[$moduleName] = array(); 
    75                 } 
    76  
    77                 $strings[$moduleName][$template] = array(); 
     94                $strings[$template] = array(); 
    7895              } 
    7996 
    80               $strings[$moduleName][$template][] = $node->nodeValue; 
     97              $strings[$template][] = $node->nodeValue; 
    8198            } 
    8299          } 
     
    92109    } 
    93110 
    94     foreach ($strings as $moduleName => $templateStrings) 
     111    foreach ($strings as $template => $messages) 
    95112    { 
    96       foreach ($templateStrings as $template => $messages) 
     113      $this->logSection('i18n', sprintf('strings in "%s"', str_replace(sfConfig::get('sf_root_dir'), '', $template)), 1000); 
     114      foreach ($messages as $message) 
    97115      { 
    98         $this->logSection('i18n', sprintf('strings in "%s:%s"', $moduleName, $template)); 
    99         foreach ($messages as $message) 
    100         { 
    101           $this->log("  $message\n"); 
    102         } 
     116        $this->log("  $message\n"); 
    103117      } 
    104118    }