sfI18nModuleExtract.class.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * @package symfony
  11. * @subpackage i18n
  12. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  13. * @version SVN: $Id: sfI18nModuleExtract.class.php 7691 2008-02-29 16:56:22Z fabien $
  14. */
  15. class sfI18nModuleExtract extends sfI18nExtract
  16. {
  17. protected $module = '';
  18. /**
  19. * Configures the current extract object.
  20. */
  21. public function configure()
  22. {
  23. if (!isset($this->parameters['module']))
  24. {
  25. throw new sfException('You must give a "module" parameter when extracting for a module.');
  26. }
  27. $this->module = $this->parameters['module'];
  28. $this->i18n->setMessageSource($this->i18n->getConfiguration()->getI18NDirs($this->module), $this->culture);
  29. }
  30. /**
  31. * Extracts i18n strings.
  32. *
  33. * This class must be implemented by subclasses.
  34. */
  35. public function extract()
  36. {
  37. // Extract from PHP files to find __() calls in actions/ lib/ and templates/ directories
  38. $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$this->module;
  39. $this->extractFromPhpFiles(array(
  40. $moduleDir.'/actions',
  41. $moduleDir.'/lib',
  42. $moduleDir.'/templates',
  43. ));
  44. // Extract from generator.yml files
  45. $generator = $moduleDir.'/config/generator.yml';
  46. if (file_exists($generator))
  47. {
  48. $yamlExtractor = new sfI18nYamlGeneratorExtractor();
  49. $this->updateMessages($yamlExtractor->extract(file_get_contents($generator)));
  50. }
  51. // Extract from validate/*.yml files
  52. $validateFiles = glob($moduleDir.'/validate/*.yml');
  53. if (is_array($validateFiles))
  54. {
  55. foreach ($validateFiles as $validateFile)
  56. {
  57. $yamlExtractor = new sfI18nYamlValidateExtractor();
  58. $this->updateMessages($yamlExtractor->extract(file_get_contents($validateFile)));
  59. }
  60. }
  61. }
  62. }