Author: david
Date: Tue Nov  8 12:40:06 2011
New Revision: 10287

Log:
Create task to read XLIFF files and write translation strings to data/fixtures

Added:
   trunk/lib/task/i18nUpdateFixturesTask.class.php
      - copied, changed from r10286, 
trunk/lib/task/i18nRemoveDuplicatesTask.class.php

Copied and modified: trunk/lib/task/i18nUpdateFixturesTask.class.php (from 
r10286, trunk/lib/task/i18nRemoveDuplicatesTask.class.php)
==============================================================================
--- trunk/lib/task/i18nRemoveDuplicatesTask.class.php   Tue Nov  8 10:01:04 
2011        (r10286, copy source)
+++ trunk/lib/task/i18nUpdateFixturesTask.class.php     Tue Nov  8 12:40:06 
2011        (r10287)
@@ -26,25 +26,30 @@
  * @author     David Juhasz <[email protected]>
  * @version    SVN: $Id$
  */
-class I18nRemoveDuplicatesTask extends sfBaseTask
+class I18nUpdateFixturesTask extends sfBaseTask
 {
   /**
    * @see sfTask
    */
   protected function configure()
   {
+    $this->addArguments(array(
+      new sfCommandArgument('path', sfCommandArgument::REQUIRED, 'Path for 
xliff files'),
+    ));
+
     $this->addOptions(array(
       // http://trac.symfony-project.org/ticket/8352
       new sfCommandOption('application', null, 
sfCommandOption::PARAMETER_REQUIRED, 'The application name', true),
       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 
'The environment', 'cli'),
+      new sfCommandArgument('filename', 'fixtures.xml', 
sfCommandOption::PARAMETER_OPTIONAL, 'Name of xliff files'),
     ));
 
     $this->namespace = 'i18n';
-    $this->name = 'remove-duplicates';
-    $this->briefDescription = 'Delete duplicate source messages';
+    $this->name = 'update-fixtures';
+    $this->briefDescription = 'Reads XLIFF files from {{path}} and merges 
translations to database fixture files';
 
     $this->detailedDescription = <<<EOF
-FIXME
+Reads XLIFF files from {{path}} and merges translations to database fixture 
files
 EOF;
   }
 
@@ -53,75 +58,9 @@
    */
   public function execute($arguments = array(), $options = array())
   {
-    $this->logSection('i18n', sprintf('Removing duplicate i18n sources for the 
"%s" application', $options['application']));
+    $this->logSection('i18n', sprintf('Reading XLIFF files'));
 
     // 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('Removing %s duplicates', 
$pluginName));
-
-      foreach 
(sfFinder::type('files')->in(sfConfig::get('sf_plugins_dir').'/'.$pluginName.'/i18n')
 as $file)
-      {
-        self::deleteDuplicateSource($file);
-      }
-    }
   }
-
-  public function deleteDuplicateSource($filename)
-  {
-    $modified = false;
-
-    // create a new dom, import the existing xml
-    $doc = new DOMDocument;
-    $doc->formatOutput = true;
-    $doc->preserveWhiteSpace = false;
-    $doc->load($filename);
-
-    $xpath = new DOMXPath($doc);
-
-    foreach ($xpath->query('//trans-unit') as $unit)
-    {
-      foreach ($xpath->query('./target', $unit) as $target)
-      {
-        break; // Only one target
-      }
-
-      foreach ($xpath->query('./source', $unit) as $source)
-      {
-        // If this is a duplicate source key, then delete it
-        if (isset($sourceStrings[$source->nodeValue]))
-        {
-          // If original target string is null, but *this* node has a valid
-          // translation
-          if (0 == strlen($sourceStrings[$source->nodeValue]->nodeValue) &&
-            0 < strlen($target->nodeValue))
-          {
-            // Copy this translated string to the trans-unit node we are 
keeping
-            $sourceStrings[$source->nodeValue]->nodeValue = $target->nodeValue;
-          }
-
-          // Remove duplicate
-          $unit->parentNode->removeChild($unit);
-          $modified = true;
-        }
-        else
-        {
-          $sourceStrings[$source->nodeValue] = $target;
-        }
-
-        break; // Only one source
-      }
-    }
-
-    // Update xliff file if modified
-    if ($modified)
-    {
-      $fileNode = $xpath->query('//file')->item(0);
-      $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
-      $doc->save($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