Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * @package    symfony
13
 * @subpackage i18n
14
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
15
 * @version    SVN: $Id: sfI18nYamlGeneratorExtractor.class.php 28848 2010-03-29 09:37:05Z fabien $
16
 */
17
class sfI18nYamlGeneratorExtractor extends sfI18nYamlExtractor
18
{
19
  protected $strings = array();
20
 
21
  /**
22
   * Extract i18n strings for the given content.
23
   *
24
   * @param  string $content The content
25
   *
26
   * @return array An array of i18n strings
27
   */
28
  public function extract($content)
29
  {
30
    $this->strings = array();
31
 
32
    $config = sfYaml::load($content);
33
 
34
    if (!isset($config['generator']['param']['config']))
35
    {
36
      return array();
37
    }
38
 
39
    $params = $config['generator']['param']['config'];
40
 
41
    // titles
42
    foreach (array('list', 'edit', 'new') as $section)
43
    {
44
      if (isset($params[$section]['title']))
45
      {
46
        $this->strings[] = $params[$section]['title'];
47
      }
48
    }
49
 
50
    // names and help messages
51
    if (isset($params['fields']))
52
    {
53
      $this->getFromFields($params['fields']);
54
    }
55
 
56
    if (isset($params['list']['fields']))
57
    {
58
      $this->getFromFields($params['list']['fields']);
59
    }
60
 
61
    if (isset($params['edit']['fields']))
62
    {
63
      $this->getFromFields($params['edit']['fields']);
64
    }
65
 
66
    if (isset($params['new']['fields']))
67
    {
68
      $this->getFromFields($params['new']['fields']);
69
    }
70
 
71
    // form categories
72
    foreach (array('edit', 'new') as $section)
73
    {
74
      if (isset($params[$section]['display']) && !isset($params[$section]['display'][0]))
75
      {
76
        foreach (array_keys($params[$section]['display']) as $string)
77
        {
78
          if ('NONE' != $string)
79
          {
80
            $this->strings[] = $string;
81
          }
82
        }
83
      }
84
    }
85
 
86
    return $this->strings;
87
  }
88
 
89
  protected function getFromFields($fields)
90
  {
91
    foreach ($fields as $field => $options)
92
    {
93
      if (isset($options['name']))
94
      {
95
        $this->strings[] = $options['name'];
96
      }
97
 
98
      if (isset($options['label']))
99
      {
100
        $this->strings[] = $options['label'];
101
      }
102
 
103
      if (isset($options['help']))
104
      {
105
        $this->strings[] = $options['help'];
106
      }
107
    }
108
  }
109
}