* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Extracts i18n strings from php files. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfI18nExtractTask.class.php 9883 2008-06-26 09:04:13Z FabianLange $ */ class sfI18nExtractTask extends sfBaseTask { /** * @see sfTask */ protected function configure() { $this->addArguments(array( new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), new sfCommandArgument('culture', sfCommandArgument::REQUIRED, 'The target culture'), )); $this->addOptions(array( new sfCommandOption('display-new', null, sfCommandOption::PARAMETER_NONE, 'Output all new found strings'), new sfCommandOption('display-old', null, sfCommandOption::PARAMETER_NONE, 'Output all old strings'), new sfCommandOption('auto-save', null, sfCommandOption::PARAMETER_NONE, 'Save the new strings'), new sfCommandOption('auto-delete', null, sfCommandOption::PARAMETER_NONE, 'Delete old strings'), )); $this->namespace = 'i18n'; $this->name = 'extract'; $this->briefDescription = 'Extracts i18n strings from php files'; $this->detailedDescription = <<logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $arguments['application'])); // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); $extract = new sfI18nApplicationExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture']); $extract->extract(); $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages()))); $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages()))); if ($options['display-new']) { $this->logSection('i18n', sprintf('display new i18n strings', count($extract->getOldMessages()))); foreach ($extract->getNewMessages() as $message) { $this->log(' '.$message."\n"); } } if ($options['auto-save']) { $this->logSection('i18n', 'saving new i18n strings'); $extract->saveNewMessages(); } if ($options['display-old']) { $this->logSection('i18n', sprintf('display old i18n strings', count($extract->getOldMessages()))); foreach ($extract->getOldMessages() as $message) { $this->log(' '.$message."\n"); } } if ($options['auto-delete']) { $this->logSection('i18n', 'deleting old i18n strings'); $extract->deleteOldMessages(); } } }