Author: david
Date: Fri Apr 27 16:15:56 2012
New Revision: 11534
Log:
Save all translatable YAML strings from data/fixtures to consolidated XLIFF
file. Fixes issue 2163
Modified:
trunk/lib/model/QubitSlug.php
trunk/lib/task/i18n/i18nConsolidateTask.class.php
Modified: trunk/lib/model/QubitSlug.php
==============================================================================
--- trunk/lib/model/QubitSlug.php Fri Apr 27 00:02:55 2012 (r11533)
+++ trunk/lib/model/QubitSlug.php Fri Apr 27 16:15:56 2012 (r11534)
@@ -29,12 +29,12 @@
//
http://en.wikipedia.org/wiki/Birthday_paradox#Cast_as_a_collision_problem
//
// Force max random value of 2^31-1 (32-bit signed integer max).
- //
+ //
// With 2^31 possible values, the probability of collision is >50% when we
// reach approx. 50,000 records
$rand = mt_rand(0, pow(2, 31)-1);
- // Convert $rand to base36 hash
+ // Convert $rand to base36 hash
while (36 < $rand)
{
$slug .= $alphabet[$rand % 36];
Modified: trunk/lib/task/i18n/i18nConsolidateTask.class.php
==============================================================================
--- trunk/lib/task/i18n/i18nConsolidateTask.class.php Fri Apr 27 00:02:55
2012 (r11533)
+++ trunk/lib/task/i18n/i18nConsolidateTask.class.php Fri Apr 27 16:15:56
2012 (r11534)
@@ -71,7 +71,7 @@
$params = $config['i18n']['param'];
unset($params['cache']);
- // Extract i18n messages from php files (including plugins)
+ // Extract i18n messages from php and yaml files (including plugins)
$i18n = new $class($this->configuration, new sfNoCache(), $params);
$extract = new sfI18nConsolidatedExtract($i18n, $arguments['culture']);
$extract->extract();
@@ -88,7 +88,7 @@
{
protected
$messageSource = array(),
- $sourceFile = array();
+ $sourceFiles = array();
public function configure()
{
@@ -115,6 +115,17 @@
}
}
+ // Get messages from data/fixtures
+ foreach
($this->getTranslationsFromYaml(sfConfig::get('sf_data_dir').'/fixtures') as
$key => $values)
+ {
+ $messages[] = $key;
+
+ if (!isset($translates[$key]) || 0 == strlen($translates[$key][0]))
+ {
+ $translates[$key] = $values;
+ }
+ }
+
// Sort and remove duplicates
$messages = array_unique($messages);
sort($messages);
@@ -133,9 +144,9 @@
{
// Track source file for message in comments
$comment = $item[2];
- if (isset($this->sourceFile[$key]))
+ if (isset($this->sourceFiles[$key]))
{
- $comment = $this->sourceFile[$key];
+ $comment = $this->sourceFiles[$key];
}
$consolidated->getMessageSource()->update($key, $item[0], $comment);
@@ -164,9 +175,6 @@
));
}
- // Extract from fixtures
- $this->extractFromFixtures(sfConfig::get('sf_data_dir').'/fixtures');
-
// Extract plugin strings
$plugins =
sfFinder::type('dir')->maxdepth(0)->not_name('.')->in(sfConfig::get('sf_plugins_dir'));
foreach ($plugins as $plugin)
@@ -180,12 +188,6 @@
$piModule.'/templates',
));
}
-
- // fixtures
- if (file_exists($plugin.'/data/fixtures'))
- {
- $this->extractFromFixtures($plugin.'/data/fixtures');
- }
}
}
@@ -208,10 +210,10 @@
// Track source file for all messages
foreach ($extracted as $message)
{
- if (!isset($this->sourceFile[$message]))
+ if (!isset($this->sourceFiles[$message]))
{
// Link to file in googlecode repository
- $this->sourceFile[$message] =
str_replace(sfConfig::get('sf_web_dir'),
'http://code.google.com/p/qubit-toolkit/source/browse/trunk', $file);
+ $this->sourceFiles[$message] =
str_replace(sfConfig::get('sf_web_dir'),
'http://code.google.com/p/qubit-toolkit/source/browse/trunk', $file);
}
}
}
@@ -224,7 +226,7 @@
*
* @param string $dir The PHP full path name
*/
- protected function extractFromFixtures($dir)
+ protected function getTranslationsFromYaml($dir)
{
// Search for YAML files
$files = sfFinder::type('file')->name('*.yml')->in($dir);
@@ -236,8 +238,7 @@
return;
}
- // Merge translations to YAML files in data/fixtures
- $messages = array();
+ $translations = array();
foreach ($files as $file)
{
$yaml = new sfYaml;
@@ -251,22 +252,49 @@
// Descend through fixtures hierarchy
foreach ($fixtures as $classname => $fixture)
{
- foreach ($fixture as $key => &$columns)
+ foreach ($fixture as $key => $item)
{
- foreach ($columns as $column => &$value)
+ $values = null;
+
+ // translated column varies by object type
+ switch ($classname)
+ {
+ case 'QubitAclGroup':
+ case 'QubitTaxonomy':
+ case 'QubitTerm':
+ $values = $item['name'];
+ break;
+
+ case 'QubitMenu':
+ $values = $item['label'];
+ break;
+
+ case 'QubitSetting':
+ $values = $item['value'];
+ break;
+ }
+
+ // Ignore non-i18n values
+ if (!isset($values) || !is_array($values) || !isset($values['en']))
{
- if (is_array($value) && isset($value['en']))
- {
- $messages[] = $value['en'];
-
- // Link to file in googlecode repository
- $this->sourceFile[$value['en']] =
str_replace(sfConfig::get('sf_web_dir'),
'http://code.google.com/p/qubit-toolkit/source/browse/trunk', $file);
- }
+ continue;
}
+
+ $target = null;
+ if (isset($values[$this->culture]))
+ {
+ $target = $values[$this->culture];
+ }
+
+ // Mimic XLIFF translation array structure: (target, id, note)
+ $translations[$values['en']] = array(
+ $target,
+ null,
+ str_replace(sfConfig::get('sf_web_dir'),
'http://code.google.com/p/qubit-toolkit/source/browse/trunk', $file));
}
}
}
- $this->updateMessages($messages);
+ return $translations;
}
}
--
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.