Author: david
Date: Tue Nov  8 17:02:01 2011
New Revision: 10293

Log:
Fiinish code to write updated YAML files

Modified:
   trunk/lib/task/i18nUpdateFixturesTask.class.php

Modified: trunk/lib/task/i18nUpdateFixturesTask.class.php
==============================================================================
--- trunk/lib/task/i18nUpdateFixturesTask.class.php     Tue Nov  8 16:33:12 
2011        (r10292)
+++ trunk/lib/task/i18nUpdateFixturesTask.class.php     Tue Nov  8 17:02:01 
2011        (r10293)
@@ -58,10 +58,10 @@
    */
   public function execute($arguments = array(), $options = array())
   {
-    // Extract translation string from XLIFF files
+    // Extract translation strings from XLIFF files
     $translations = $this->extractTranslations($arguments, $options);
 
-    var_dump($translations);
+    $this->updateFixtures($translations);
   }
 
   protected function extractTranslations($arguments = array(), $options = 
array())
@@ -101,8 +101,10 @@
     return $translations;
   }
 
-  protected static function writeYamlFiles()
+  protected function updateFixtures($translations)
   {
+    $this->logSection('i18n', 'Writing new translations to fixtures...');
+
     // Search for YAML files
     $fixturesDirs = 
array_merge(array(sfConfig::get('sf_data_dir').'/fixtures'), 
$this->configuration->getPluginSubPaths('/data/fixtures'));
     $files = sfFinder::type('file')->name('*.yml')->in($fixturesDirs);
@@ -114,10 +116,50 @@
       return;
     }
 
-    // Write translations to YAML files in data/fixtures
+    // Merge translations to YAML files in data/fixtures
     foreach ($files as $file)
     {
+      $modified = false;
+      $yaml = new sfYaml;
+      $fixtures = $yaml->load($file);
+
+      // Descend through fixtures hierarchy
+      foreach ($fixtures as $classname => &$fixture)
+      {
+        foreach ($fixture as $key => &$columns)
+        {
+          foreach ($columns as $column => &$value)
+          {
+            if (is_array($value) && isset($value['en']))
+            {
+              if (isset($translations[$value['en']]))
+              {
+                $value = array_merge($value, $translations[$value['en']]);
+
+                // Sort keys alphabetically
+                ksort($value);
+
+                $modified = true;
+              }
+            }
+          }
+        }
+      }
+
+      if ($modified)
+      {
+        $this->logSection('i18n', sprintf('Updating %s...', $file));
+
+        $contents = $yaml->dump($fixtures, 4);
+
+        if (0 < strlen($contents))
+        {
+          file_put_contents($file, $contents);
+        }
+      }
     }
+
+    return $this;
   }
 
   protected static function getTargetCulture($filename)

-- 
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.

Reply via email to