Changeset 8452
- Timestamp:
- 04/14/08 17:28:10 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/task/i18n/sfI18nFindTask.class.php
r8148 r8452 37 37 38 38 $this->detailedDescription = <<<EOF 39 The [i18n:find|INFO] task finds non internationalized strings embedded in templates: 40 41 [./symfony i18n:find frontend|INFO] 42 43 This 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 47 But it can't find strings embedded in PHP code like this one: 48 49 <p><?php echo 'Test' ?></p> 39 50 EOF; 40 51 } … … 48 59 49 60 // Look in templates 61 $dirs = array(); 50 62 $moduleNames = sfFinder::type('dir')->maxdepth(0)->relative()->in(sfConfig::get('sf_app_module_dir')); 51 $strings = array();52 63 foreach ($moduleNames as $moduleName) 53 64 { 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); 56 73 foreach ($templates as $template) 57 74 { 58 75 $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>'); 60 82 61 83 $nodes = array($dom); … … 68 90 if (!$node->isWhitespaceInElementContent()) 69 91 { 70 if (!isset($strings[$ moduleName][$template]))92 if (!isset($strings[$template])) 71 93 { 72 if (!isset($strings[$moduleName])) 73 { 74 $strings[$moduleName] = array(); 75 } 76 77 $strings[$moduleName][$template] = array(); 94 $strings[$template] = array(); 78 95 } 79 96 80 $strings[$ moduleName][$template][] = $node->nodeValue;97 $strings[$template][] = $node->nodeValue; 81 98 } 82 99 } … … 92 109 } 93 110 94 foreach ($strings as $ moduleName => $templateStrings)111 foreach ($strings as $template => $messages) 95 112 { 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) 97 115 { 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"); 103 117 } 104 118 }