Development

/branches/1.2/lib/i18n/extract/sfI18nYamlValidateExtractor.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/i18n/extract/sfI18nYamlValidateExtractor.class.php

Revision 9128, 2.3 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 sfI18nYamlValidateExtractor extends sfI18nYamlExtractor
18 {
19   /**
20    * Extract i18n strings for the given content.
21    *
22    * @param  string $content The content
23    *
24    * @return array An array of i18n strings
25    */
26   public function extract($content)
27   {
28     $strings = array();
29
30     $config = sfYaml::load($content);
31
32     // New validate.yml format
33
34     // fields
35     if (isset($config['fields']))
36     {
37       foreach ($config['fields'] as $field => $validation)
38       {
39         foreach ($validation as $type => $parameters)
40         {
41           if (!is_array($parameters))
42           {
43             continue;
44           }
45
46           foreach ($parameters as $key => $value)
47           {
48             if (preg_match('/(msg|error)$/', $key))
49             {
50               $strings[] = $value;
51             }
52           }
53         }
54       }
55     }
56
57     // validators
58     if (isset($config['validators']))
59     {
60       foreach (array_keys($config['validators']) as $name)
61       {
62         if (!isset($config['validators'][$name]['param']))
63         {
64           continue;
65         }
66
67         foreach ($config['validators'][$name]['param'] as $key => $value)
68         {
69           if (preg_match('/(msg|error)$/', $key))
70           {
71             $strings[] = $value;
72           }
73         }
74       }
75     }
76
77     // Old validate.yml format
78
79     // required messages
80     if (isset($config['names']))
81     {
82       foreach ($config['names'] as $key => $value)
83       {
84         if (isset($value['required_msg']))
85         {
86           $strings[] = $value['required_msg'];
87         }
88       }
89     }
90
91     // validators
92     foreach ($config as $key => $value)
93     {
94       if (isset($value['param']) && isset($value['class']))
95       {
96         foreach ($value['param'] as $key => $value)
97         {
98           if (preg_match('/(msg|error)$/', $key))
99           {
100             $strings[] = $value;
101           }
102         }
103       }
104     }
105
106     return $strings;
107   }
108 }
109
Note: See TracBrowser for help on using the browser.