Development

/branches/1.1/lib/task/i18n/sfI18nExtractTask.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/task/i18n/sfI18nExtractTask.class.php

Revision 9883, 4.3 kB (checked in by FabianLange, 6 years ago)

fixed typo in task help

  • 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  * Current known limitations:
5  *   - Can only works with the default "messages" catalogue
6  *   - For file backends (XLIFF and gettext), it only saves/deletes strings in the "most global" file
7  */
8
9 /*
10  * This file is part of the symfony package.
11  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
12  *
13  * For the full copyright and license information, please view the LICENSE
14  * file that was distributed with this source code.
15  */
16
17 /**
18  * Extracts i18n strings from php files.
19  *
20  * @package    symfony
21  * @subpackage task
22  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
23  * @version    SVN: $Id$
24  */
25 class sfI18nExtractTask extends sfBaseTask
26 {
27   /**
28    * @see sfTask
29    */
30   protected function configure()
31   {
32     $this->addArguments(array(
33       new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
34       new sfCommandArgument('culture', sfCommandArgument::REQUIRED, 'The target culture'),
35     ));
36
37     $this->addOptions(array(
38       new sfCommandOption('display-new', null, sfCommandOption::PARAMETER_NONE, 'Output all new found strings'),
39       new sfCommandOption('display-old', null, sfCommandOption::PARAMETER_NONE, 'Output all old strings'),
40       new sfCommandOption('auto-save', null, sfCommandOption::PARAMETER_NONE, 'Save the new strings'),
41       new sfCommandOption('auto-delete', null, sfCommandOption::PARAMETER_NONE, 'Delete old strings'),
42     ));
43
44     $this->namespace = 'i18n';
45     $this->name = 'extract';
46     $this->briefDescription = 'Extracts i18n strings from php files';
47
48     $this->detailedDescription = <<<EOF
49 The [i18n:extract|INFO] task extracts i18n strings from your project files
50 for the given application and target culture:
51
52   [./symfony i18n:extract frontend fr|INFO]
53
54 By default, the task only displays the number of new and old strings
55 it found in the current project.
56
57 If you want to display the new strings, use the [--display-new|COMMENT] option:
58
59   [./symfony i18n:extract --display-new frontend fr|INFO]
60
61 To save them in the i18n message catalogue, use the [--auto-save|COMMENT] option:
62
63   [./symfony i18n:extract --auto-save frontend fr|INFO]
64
65 If you want to display strings that are present in the i18n messages
66 catalogue but are not found in the application, use the
67 [--display-old|COMMENT] option:
68
69   [./symfony i18n:extract --display-old frontend fr|INFO]
70
71 To automatically delete old strings, use the [--auto-delete|COMMENT] but
72 be careful, especially if you have translations for plugins as they will
73 appear as old strings but they are not:
74
75   [./symfony i18n:extract --auto-delete frontend fr|INFO]
76 EOF;
77   }
78
79   /**
80    * @see sfTask
81    */
82   public function execute($arguments = array(), $options = array())
83   {
84     $this->logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $arguments['application']));
85
86     // get i18n configuration from factories.yml
87     $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml'));
88
89     $class = $config['i18n']['class'];
90     $params = $config['i18n']['param'];
91     unset($params['cache']);
92
93     $extract = new sfI18nApplicationExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture']);
94     $extract->extract();
95
96     $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages())));
97     $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages())));
98
99     if ($options['display-new'])
100     {
101       $this->logSection('i18n', sprintf('display new i18n strings', count($extract->getOldMessages())));
102       foreach ($extract->getNewMessages() as $message)
103       {
104         $this->log('               '.$message."\n");
105       }
106     }
107
108     if ($options['auto-save'])
109     {
110       $this->logSection('i18n', 'saving new i18n strings');
111
112       $extract->saveNewMessages();
113     }
114
115     if ($options['display-old'])
116     {
117       $this->logSection('i18n', sprintf('display old i18n strings', count($extract->getOldMessages())));
118       foreach ($extract->getOldMessages() as $message)
119       {
120         $this->log('               '.$message."\n");
121       }
122     }
123
124     if ($options['auto-delete'])
125     {
126       $this->logSection('i18n', 'deleting old i18n strings');
127
128       $extract->deleteOldMessages();
129     }
130   }
131 }
132
Note: See TracBrowser for help on using the browser.