* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBNLS_Extractor'); /** * Native Lanauge Support: Extractor Html Template * * Extract translatable strings from patTemplate templates. * * @version 0.1.0 * @package WB * @subpackage nls */ class WBNLS_Extractor_HtmlTemplate extends WBNLS_Extractor { /** * markup scanner * @var WBMarkup_Scanner */ private $scanner; /** * markup handler * @var WBMarkup_Handler_I18nExtractor */ private $handler; /** * setup extractor * * Start scanner and handler * * @see WBMarkup_Handler_I18nExtractor_HtmlTemplate * @see WBMarkup_Scanner */ protected function onStart() { $this->scanner = WBClass::create('WBMarkup_Scanner'); $this->handler = WBClass::create('WBMarkup_Handler_I18nExtractor_HtmlTemplate'); $this->handler->setImporter($this->imp); $this->scanner->setHandler($this->handler); } /** * actually extract messages * * Extract messages from all templates in template folder * * @return int $total */ protected function extract() { $cnt = 0; $dirs = array( 'template', 'resource/latex' ); $resources = array(); $resources = WBParam::get('wb/dir/resource'); $resources[] = WBParam::get('wb/dir/base'); foreach ($dirs as $d) { foreach ($resources as $rd) { $dir = sprintf('%s/%s', $rd, $d); if (is_dir($dir)) { $cnt += $this->extractTemplateDir($dir); } } } return $cnt; } /** * tear down extractor */ protected function onEnd() { } /** * recursively extract messages from template folders * * Walk through all template folders and scann all template files. * The markup scanner handler will acatually import found messages. * * @param string $dir template folder to scan * @return int $total number of scanned files */ private function extractTemplateDir($dir) { $cnt = 0; $dh = new DirectoryIterator($dir); foreach ($dh as $i) { $name = $i->getFilename(); if ($i->isDot() || '.' == $name[0]) { continue; } $path = $i->getRealpath(); // recursion if ($i->isDir()) { $cnt += $this->extractTemplateDir($path); continue; } $name = explode('.', $name); if ('tmpl' != end($name)) { continue; } $this->scanner->scanFile($path); ++$cnt; } return $cnt; } } ?>