sfI18nApplicationExtract.class.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: sfI18nApplicationExtract.class.php 14872 2009-01-19 08:32:06Z fabien $
  14. */
  15. class sfI18nApplicationExtract extends sfI18nExtract
  16. {
  17. protected $extractObjects = array();
  18. /**
  19. * Configures the current extract object.
  20. */
  21. public function configure()
  22. {
  23. $this->extractObjects = array();
  24. // Modules
  25. $moduleNames = sfFinder::type('dir')->maxdepth(0)->relative()->in(sfConfig::get('sf_app_module_dir'));
  26. foreach ($moduleNames as $moduleName)
  27. {
  28. $this->extractObjects[] = new sfI18nModuleExtract($this->i18n, $this->culture, array('module' => $moduleName));
  29. }
  30. }
  31. /**
  32. * Extracts i18n strings.
  33. *
  34. * This class must be implemented by subclasses.
  35. */
  36. public function extract()
  37. {
  38. foreach ($this->extractObjects as $extractObject)
  39. {
  40. $extractObject->extract();
  41. }
  42. // Add global templates
  43. $this->extractFromPhpFiles(sfConfig::get('sf_app_template_dir'));
  44. // Add global librairies
  45. $this->extractFromPhpFiles(sfConfig::get('sf_app_lib_dir'));
  46. }
  47. /**
  48. * Gets the current i18n strings.
  49. */
  50. public function getCurrentMessages()
  51. {
  52. return array_unique(array_merge($this->currentMessages, $this->aggregateMessages('getCurrentMessages')));
  53. }
  54. /**
  55. * Gets all i18n strings seen during the extraction process.
  56. */
  57. public function getAllSeenMessages()
  58. {
  59. return array_unique(array_merge($this->allSeenMessages, $this->aggregateMessages('getAllSeenMessages')));
  60. }
  61. protected function aggregateMessages($method)
  62. {
  63. $messages = array();
  64. foreach ($this->extractObjects as $extractObject)
  65. {
  66. $messages = array_merge($messages, $extractObject->$method());
  67. }
  68. return array_unique($messages);
  69. }
  70. }