sfI18nYamlGeneratorExtractor.class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: sfI18nYamlGeneratorExtractor.class.php 9128 2008-05-21 00:58:19Z Carl.Vondrick $
  14. */
  15. class sfI18nYamlGeneratorExtractor extends sfI18nYamlExtractor
  16. {
  17. protected $strings = array();
  18. /**
  19. * Extract i18n strings for the given content.
  20. *
  21. * @param string $content The content
  22. *
  23. * @return array An array of i18n strings
  24. */
  25. public function extract($content)
  26. {
  27. $this->strings = array();
  28. $config = sfYaml::load($content);
  29. if (!isset($config['generator']['param']))
  30. {
  31. return array();
  32. }
  33. $params = $config['generator']['param'];
  34. // titles
  35. if (isset($params['list']['title']))
  36. {
  37. $this->strings[] = $params['list']['title'];
  38. }
  39. if (isset($params['edit']['title']))
  40. {
  41. $this->strings[] = $params['edit']['title'];
  42. }
  43. // names and help messages
  44. if (isset($params['fields']))
  45. {
  46. $this->getFromFields($params['fields']);
  47. }
  48. if (isset($params['list']['fields']))
  49. {
  50. $this->getFromFields($params['list']['fields']);
  51. }
  52. if (isset($params['edit']['fields']))
  53. {
  54. $this->getFromFields($params['edit']['fields']);
  55. }
  56. // edit categories
  57. if (isset($params['edit']['display']) && !isset($params['edit']['display'][0]))
  58. {
  59. foreach (array_keys($params['edit']['display']) as $string)
  60. {
  61. if ('NONE' == $string)
  62. {
  63. continue;
  64. }
  65. $this->strings[] = $string;
  66. }
  67. }
  68. return $this->strings;
  69. }
  70. protected function getFromFields($fields)
  71. {
  72. foreach ($fields as $field => $options)
  73. {
  74. if (isset($options['name']))
  75. {
  76. $this->strings[] = $options['name'];
  77. }
  78. if (isset($options['help']))
  79. {
  80. $this->strings[] = $options['help'];
  81. }
  82. }
  83. }
  84. }