1. sfI18nExtractTask.class.php
  2. /** * 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 $ */
  3. class sfI18nExtractTask extends sfBaseTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addArguments(array(
  11. new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
  12. new sfCommandArgument('culture', sfCommandArgument::REQUIRED, 'The target culture'),
  13. ));
  14. $this->addOptions(array(
  15. new sfCommandOption('display-new', null, sfCommandOption::PARAMETER_NONE, 'Output all new found strings'),
  16. new sfCommandOption('display-old', null, sfCommandOption::PARAMETER_NONE, 'Output all old strings'),
  17. new sfCommandOption('auto-save', null, sfCommandOption::PARAMETER_NONE, 'Save the new strings'),
  18. new sfCommandOption('auto-delete', null, sfCommandOption::PARAMETER_NONE, 'Delete old strings'),
  19. ));
  20. $this->namespace = 'i18n';
  21. $this->name = 'extract';
  22. $this->briefDescription = 'Extracts i18n strings from php files';
  23. $this->detailedDescription = <<<EOF
  24. The [i18n:extract|INFO] task extracts i18n strings from your project files
  25. for the given application and target culture:
  26. [./symfony i18n:extract frontend fr|INFO]
  27. By default, the task only displays the number of new and old strings
  28. it found in the current project.
  29. If you want to display the new strings, use the [--display-new|COMMENT] option:
  30. [./symfony i18n:extract --display-new frontend fr|INFO]
  31. To save them in the i18n message catalogue, use the [--auto-save|COMMENT] option:
  32. [./symfony i18n:extract --auto-save frontend fr|INFO]
  33. If you want to display strings that are present in the i18n messages
  34. catalogue but are not found in the application, use the
  35. [--display-old|COMMENT] option:
  36. [./symfony i18n:extract --display-old frontend fr|INFO]
  37. To automatically delete old strings, use the [--auto-delete|COMMENT] but
  38. be careful, especially if you have translations for plugins as they will
  39. appear as old strings but they are not:
  40. [./symfony i18n:extract --auto-delete frontend fr|INFO]
  41. EOF;
  42. }
  43. /**
  44. * @see sfTask
  45. */
  46. public function execute($arguments = array(), $options = array())
  47. {
  48. $this->logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $arguments['application']));
  49. // get i18n configuration from factories.yml
  50. $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml'));
  51. $class = $config['i18n']['class'];
  52. $params = $config['i18n']['param'];
  53. unset($params['cache']);
  54. $extract = new sfI18nApplicationExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture']);
  55. $extract->extract();
  56. $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages())));
  57. $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages())));
  58. if ($options['display-new'])
  59. {
  60. $this->logSection('i18n', sprintf('display new i18n strings', count($extract->getOldMessages())));
  61. foreach ($extract->getNewMessages() as $message)
  62. {
  63. $this->log(' '.$message."\n");
  64. }
  65. }
  66. if ($options['auto-save'])
  67. {
  68. $this->logSection('i18n', 'saving new i18n strings');
  69. $extract->saveNewMessages();
  70. }
  71. if ($options['display-old'])
  72. {
  73. $this->logSection('i18n', sprintf('display old i18n strings', count($extract->getOldMessages())));
  74. foreach ($extract->getOldMessages() as $message)
  75. {
  76. $this->log(' '.$message."\n");
  77. }
  78. }
  79. if ($options['auto-delete'])
  80. {
  81. $this->logSection('i18n', 'deleting old i18n strings');
  82. $extract->deleteOldMessages();
  83. }
  84. }
  85. }

Debug toolbar