Author: david
Date: Mon Sep 12 17:55:44 2011
New Revision: 9699
Log:
Commit work on task for consolidating all I18n messages into a single XLIFF file
Added:
trunk/lib/task/i18nConsolidateTask.class.php
- copied, changed from r9694, trunk/lib/task/i18nRectifyTask.class.php
Copied and modified: trunk/lib/task/i18nConsolidateTask.class.php (from r9694,
trunk/lib/task/i18nRectifyTask.class.php)
==============================================================================
--- trunk/lib/task/i18nRectifyTask.class.php Fri Sep 9 15:55:07 2011
(r9694, copy source)
+++ trunk/lib/task/i18nConsolidateTask.class.php Mon Sep 12 17:55:44
2011 (r9699)
@@ -26,7 +26,7 @@
* @author David Juhasz <[email protected]>
* @version SVN: $Id$
*/
-class i18nRectifyTask extends sfBaseTask
+class i18nConsolidateTask extends sfBaseTask
{
/**
* @see sfTask
@@ -38,17 +38,16 @@
));
$this->addOptions(array(
-
// http://trac.symfony-project.org/ticket/8352
new sfCommandOption('application', null,
sfCommandOption::PARAMETER_REQUIRED, 'The application name', true),
));
$this->namespace = 'i18n';
- $this->name = 'rectify';
- $this->briefDescription = 'Copy i18n target messages from application
source to plugin source. This prevents losing translated string in the
fragmentation of application message source into multiple plugin message
sources.';
+ $this->name = 'consolidate';
+ $this->briefDescription = 'Combine all application messages into a single
output (XLIFF) file for ease of use by translators';
$this->detailedDescription = <<<EOF
-FIXME
+Combine all application messages into a single output (XLIFF) file for ease of
use by translators.
EOF;
}
@@ -57,7 +56,7 @@
*/
public function execute($arguments = array(), $options = array())
{
- $this->logSection('i18n', sprintf('Rectifying existing i18n strings for
the "%s" application', $options['application']));
+ $this->logSection('i18n', sprintf('Consolidating i18n messages %s',
$options['filename']));
// get i18n configuration from factories.yml
$config =
sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml'));
@@ -66,41 +65,49 @@
$params = $config['i18n']['param'];
unset($params['cache']);
- // Get current (saved) messages from ALL sources (app and plugin)
- $this->i18n = new $class($this->configuration, new sfNoCache(), $params);
- $this->i18n->getMessageSource()->setCulture($arguments['culture']);
- $this->i18n->getMessageSource()->load();
+ $i18n = new $class($this->configuration, new sfNoCache(), $params);
+ $extract = new sfI18nConsolidatedExtract($i18n, $arguments['culture']);
- $currentMessages = array();
- foreach ($this->i18n->getMessageSource()->read() as $catalogue =>
$translations)
- {
- $currentMessages += $translations;
- }
+ // Extract i18n messages from php files (including plugins)
+ $extract->extract();
- // Loop through plugins
- $pluginNames =
sfFinder::type('dir')->maxdepth(0)->relative()->not_name('.')->in(sfConfig::get('sf_plugins_dir'));
- foreach ($pluginNames as $pluginName)
- {
- $this->logSection('i18n', sprintf('rectifying %s plugin strings',
$pluginName));
+ var_dump($extract->read());
+ die();
+
+ $i18n = new $class($this->configuration, new sfNoCache(), $params);
+
$i18n->setMessageSource(array(sfConfig::get('sf_app_i18n_dir').'/consolidated'),
$arguments['culture']);
- $messageSource =
sfMessageSource::factory($config['i18n']['param']['source'],
sfConfig::get('sf_plugins_dir').'/'.$pluginName.'/i18n');
- $messageSource->setCulture($arguments['culture']);
- $messageSource->load();
-
- // If the current plugin source *doesn't* have a translation, then try
- // and get translated value from $currentMessages
- foreach($messageSource->read() as $catalogue => $translations)
+ $extract->saveNewMessages();
+ }
+}
+
+class sfI18nConsolidatedExtract extends sfI18nApplicationExtract
+{
+ public function configure()
+ {
+ }
+
+ public function read()
+ {
+ return $this->i18n->getMessageSource()->read();
+ }
+
+ public function extract()
+ {
+ parent::extract();
+
+ // Extract plugin strings
+ $plugins =
sfFinder::type('dir')->maxdepth(0)->relative()->not_name('.')->in(sfConfig::get('sf_plugins_dir'));
+ foreach ($plugins as $plugin)
+ {
+ foreach
(sfFinder::type('dir')->maxdepth(0)->relative()->in(sfConfig::get('sf_plugins_dir').'/'.$plugin.'/modules')
as $piModule)
{
- foreach ($translations as $key => &$value)
- {
- if (0 == strlen($value[0]) && 0 < strlen($currentMessages[$key][0]))
- {
- $messageSource->update($key, $currentMessages[$key][0], $value[2]);
- }
- }
+ $this->extractFromPhpFiles(array(
+
sfConfig::get('sf_plugins_dir').'/'.$plugin.'/modules/'.$piModule.'/actions',
+
sfConfig::get('sf_plugins_dir').'/'.$plugin.'/modules/'.$piModule.'/lib',
+
sfConfig::get('sf_plugins_dir').'/'.$plugin.'/modules/'.$piModule.'/templates',
+ ));
}
-
- $messageSource->save();
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.