[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/i18n/src/translation/ -> lmbDictionaryUpdater.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/i18n/src/translation/lmbPHPDictionaryExtractor.class.php');
  10  lmb_require('limb/i18n/src/translation/lmbWACTDictionaryExtractor.class.php');
  11  lmb_require('limb/i18n/src/translation/lmbFsDictionaryExtractor.class.php');
  12  lmb_require('limb/i18n/src/translation/lmbI18NDictionary.class.php');
  13  lmb_require('limb/i18n/src/translation/lmbQtDictionaryBackend.class.php');
  14  lmb_require('limb/cli/src/lmbCliResponse.class.php');
  15  lmb_require('limb/fs/src/lmbFsRecursiveIterator.class.php');
  16  lmb_require('limb/fs/src/lmbFs.class.php');
  17  
  18  /**

  19   * class lmbDictionaryUpdater.

  20   *

  21   * @package i18n

  22   * @version $Id: lmbDictionaryUpdater.class.php 5945 2007-06-06 08:31:43Z pachanga $

  23   */
  24  class lmbDictionaryUpdater
  25  {
  26    protected $response;
  27  
  28    function __construct($backend, $response = null)
  29    {
  30      $this->backend = $backend;
  31      $this->response = $response ? $response : new lmbCliResponse();
  32    }
  33  
  34    function dryrun($source_dir)
  35    {
  36      $this->response->write("Dry-running in '$source_dir'...\n");
  37  
  38      $this->updateTranslations($source_dir, true);
  39    }
  40  
  41    function updateTranslations($source_dir, $dry_run = false)
  42    {
  43      $loader = new lmbFsDictionaryExtractor();
  44      $loader->registerFileParser('.html', new lmbWACTDictionaryExtractor());
  45      $loader->registerFileParser('.php', new lmbPHPDictionaryExtractor());
  46  
  47      $dicts = array();
  48      $iterator = new lmbFsRecursiveIterator($source_dir);
  49  
  50      $this->response->write("======== Extracting translations from source ========\n");
  51      $loader->traverse($iterator, $dicts, $this->response);
  52  
  53      if(!$translations = $this->backend->loadAll())
  54      {
  55        $this->response->write("======== No existing translations found!(create them first) ========\n");
  56        return;
  57      }
  58  
  59      $this->response->write("======== Updating translations ========\n");
  60  
  61      foreach($translations as $locale => $domains)
  62      {
  63        foreach($domains as $domain => $old_dict)
  64        {
  65          if(isset($dicts[$domain]))
  66          {
  67            $this->response->write($this->backend->info($locale, $domain) . "...");
  68  
  69            $new_dict = $dicts[$domain]->merge($old_dict);
  70            if(!$dry_run)
  71            {
  72              $this->backend->save($locale, $domain, $new_dict);
  73              $this->response->write("updated\n");
  74            }
  75            else
  76              $this->response->write("skipped(dry-run)\n");
  77          }
  78        }
  79      }
  80    }
  81  }
  82  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7