1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<?php
/*
* Current known limitations:
* - Can only works with the default "messages" catalogue
* - For file backends (XLIFF and gettext), it only saves/deletes strings in the "most global" file
*/
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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 <fabien.potencier@symfony-project.com>
* @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'),
/*************************************************************
* Ajouter les 2 lignes ci-dessous
**********************************************************/
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), //<--------------A rajouter
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), //<--------------A rajouter
/*************************************************************
* Fin de l'ajout
**********************************************************/
));
$this->namespace = 'i18n';
$this->name = 'extract';
$this->briefDescription = 'Extracts i18n strings from php files';
$this->detailedDescription = <<<EOF
The [i18n:extract|INFO] task extracts i18n strings from your project files
for the given application and target culture:
[./symfony i18n:extract frontend fr|INFO]
By default, the task only displays the number of new and old strings
it found in the current project.
If you want to display the new strings, use the [--display-new|COMMENT] option:
[./symfony i18n:extract --display-new frontend fr|INFO]
To save them in the i18n message catalogue, use the [--auto-save|COMMENT] option:
[./symfony i18n:extract --auto-save frontend fr|INFO]
If you want to display strings that are present in the i18n messages
catalogue but are not found in the application, use the
[--display-old|COMMENT] option:
[./symfony i18n:extract --display-old frontend fr|INFO]
To automatically delete old strings, use the [--auto-delete|COMMENT] but
be careful, especially if you have translations for plugins as they will
appear as old strings but they are not:
[./symfony i18n:extract --auto-delete frontend fr|INFO]
EOF;
}
/**
* @see sfTask
*/
public function execute($arguments = array(), $options = array())
{
$this->logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $arguments['application']));
/*************************************************************
* Ajouter les 2 lignes ci-dessous
**********************************************************/
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
/*************************************************************
* Fin de l'ajout
**********************************************************/
// 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();
}
}
} |
Partager