Development

/branches/1.1/lib/i18n/extract/sfI18nYamlGeneratorExtractor.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/i18n/extract/sfI18nYamlGeneratorExtractor.class.php

Revision 9128, 2.1 kB (checked in by Carl.Vondrick, 7 years ago)

1.1: fixed @param phpdoc to fit specs in i18n (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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$
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']))
35     {
36       return array();
37     }
38
39     $params = $config['generator']['param'];
40
41     // titles
42     if (isset($params['list']['title']))
43     {
44       $this->strings[] = $params['list']['title'];
45     }
46
47     if (isset($params['edit']['title']))
48     {
49       $this->strings[] = $params['edit']['title'];
50     }
51
52     // names and help messages
53     if (isset($params['fields']))
54     {
55       $this->getFromFields($params['fields']);
56     }
57
58     if (isset($params['list']['fields']))
59     {
60       $this->getFromFields($params['list']['fields']);
61     }
62
63     if (isset($params['edit']['fields']))
64     {
65       $this->getFromFields($params['edit']['fields']);
66     }
67
68     // edit categories
69     if (isset($params['edit']['display']) && !isset($params['edit']['display'][0]))
70     {
71       foreach (array_keys($params['edit']['display']) as $string)
72       {
73         if ('NONE' == $string)
74         {
75           continue;
76         }
77
78         $this->strings[] = $string;
79       }
80     }
81
82     return $this->strings;
83   }
84
85   protected function getFromFields($fields)
86   {
87     foreach ($fields as $field => $options)
88     {
89       if (isset($options['name']))
90       {
91         $this->strings[] = $options['name'];
92       }
93
94       if (isset($options['help']))
95       {
96         $this->strings[] = $options['help'];
97       }
98     }
99   }
100 }
101
Note: See TracBrowser for help on using the browser.