| | 19 | |
|---|
| | 20 | pake_desc('find non "i18n ready" strings in an application'); |
|---|
| | 21 | pake_task('i18n-find'); |
|---|
| | 22 | |
|---|
| | 23 | function run_i18n_find($task, $args) |
|---|
| | 24 | { |
|---|
| | 25 | if (!count($args)) |
|---|
| | 26 | { |
|---|
| | 27 | throw new Exception('You must provide the application.'); |
|---|
| | 28 | } |
|---|
| | 29 | |
|---|
| | 30 | $app = $args[0]; |
|---|
| | 31 | |
|---|
| | 32 | if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app)) |
|---|
| | 33 | { |
|---|
| | 34 | throw new Exception(sprintf('The app "%s" does not exist.', $app)); |
|---|
| | 35 | } |
|---|
| | 36 | |
|---|
| | 37 | pake_echo_action('i18n', sprintf('find non "i18n ready" strings in the "%s" application', $app)); |
|---|
| | 38 | |
|---|
| | 39 | sfConfig::set('sf_app', $app); |
|---|
| | 40 | sfConfig::set('sf_environment', 'dev'); |
|---|
| | 41 | include(sfConfig::get('sf_symfony_data_dir').'/config/constants.php'); |
|---|
| | 42 | |
|---|
| | 43 | // Look in templates |
|---|
| | 44 | $moduleNames = sfFinder::type('dir')->maxdepth(0)->ignore_version_control()->relative()->in(sfConfig::get('sf_app_dir').'/modules'); |
|---|
| | 45 | $strings = array(); |
|---|
| | 46 | foreach ($moduleNames as $moduleName) |
|---|
| | 47 | { |
|---|
| | 48 | $dir = sfConfig::get('sf_app_dir').'/modules/'.$moduleName.'/templates'; |
|---|
| | 49 | $templates = pakeFinder::type('file')->name('*.php')->relative()->in($dir); |
|---|
| | 50 | foreach ($templates as $template) |
|---|
| | 51 | { |
|---|
| | 52 | $dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8')); |
|---|
| | 53 | @$dom->loadXML('<doc>'.file_get_contents($dir.'/'.$template).'</doc>'); |
|---|
| | 54 | |
|---|
| | 55 | $nodes = array($dom); |
|---|
| | 56 | while ($nodes) |
|---|
| | 57 | { |
|---|
| | 58 | $node = array_shift($nodes); |
|---|
| | 59 | |
|---|
| | 60 | if (XML_TEXT_NODE === $node->nodeType) |
|---|
| | 61 | { |
|---|
| | 62 | if (!$node->isWhitespaceInElementContent()) |
|---|
| | 63 | { |
|---|
| | 64 | if (!isset($strings[$moduleName][$template])) |
|---|
| | 65 | { |
|---|
| | 66 | if (!isset($strings[$moduleName])) |
|---|
| | 67 | { |
|---|
| | 68 | $strings[$moduleName] = array(); |
|---|
| | 69 | } |
|---|
| | 70 | |
|---|
| | 71 | $strings[$moduleName][$template] = array(); |
|---|
| | 72 | } |
|---|
| | 73 | |
|---|
| | 74 | $strings[$moduleName][$template][] = $node->nodeValue; |
|---|
| | 75 | } |
|---|
| | 76 | } |
|---|
| | 77 | else if ($node->childNodes) |
|---|
| | 78 | { |
|---|
| | 79 | for ($i = 0, $max = $node->childNodes->length; $i < $max; $i++) |
|---|
| | 80 | { |
|---|
| | 81 | $nodes[] = $node->childNodes->item($i); |
|---|
| | 82 | } |
|---|
| | 83 | } |
|---|
| | 84 | } |
|---|
| | 85 | } |
|---|
| | 86 | } |
|---|
| | 87 | |
|---|
| | 88 | foreach ($strings as $moduleName => $templateStrings) |
|---|
| | 89 | { |
|---|
| | 90 | foreach ($templateStrings as $template => $messages) |
|---|
| | 91 | { |
|---|
| | 92 | pake_echo_action('i18n', sprintf('strings in "%s:%s"', $moduleName, $template)); |
|---|
| | 93 | foreach ($messages as $message) |
|---|
| | 94 | { |
|---|
| | 95 | echo " $message\n"; |
|---|
| | 96 | } |
|---|
| | 97 | } |
|---|
| | 98 | } |
|---|
| | 99 | } |
|---|