[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/i18n/src/translation/ -> lmbI18NDictionary.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  
  10  /**

  11   * class lmbI18NDictionary.

  12   *

  13   * @package i18n

  14   * @version $Id$

  15   */
  16  class lmbI18NDictionary
  17  {
  18    protected $translations;
  19  
  20    function __construct($translations = array())
  21    {
  22      $this->translations = $translations;
  23    }
  24  
  25    function isEmpty()
  26    {
  27      return sizeof($this->translations) == 0;
  28    }
  29  
  30    function translate($text, $attributes = array())
  31    {
  32      if(isset($this->translations[$text]) &&
  33         !empty($this->translations[$text]))
  34        $translation = $this->translations[$text];
  35      else
  36        $translation = $text;
  37  
  38      if($attributes)
  39        return str_replace(array_keys($attributes), array_values($attributes), $translation);
  40      else
  41        return $translation;
  42    }
  43  
  44    function add($text, $translation = '')
  45    {
  46      $this->translations[$text] = $translation;
  47    }
  48  
  49    function has($text)
  50    {
  51      return isset($this->translations[$text]);
  52    }
  53  
  54    function isTranslated($text)
  55    {
  56      return isset($this->translations[$text]) &&
  57             !empty($this->translations[$text]);
  58    }
  59  
  60    function setTranslations($translations)
  61    {
  62      $this->translations = $translations;
  63    }
  64  
  65    function getTranslations()
  66    {
  67      return $this->translations;
  68    }
  69  
  70    function merge($d)
  71    {
  72      $dictionary = new lmbI18NDictionary($this->getTranslations());
  73  
  74      $translations = $d->getTranslations();
  75      foreach($translations as $text => $translation)
  76        $dictionary->add($text, $translation);
  77  
  78      return $dictionary;
  79    }
  80  
  81    function hasSameEntries($d)
  82    {
  83      foreach($this->translations as $text => $translation)
  84      {
  85        if(!$d->has($text))
  86          return false;
  87      }
  88      return true;
  89    }
  90  
  91    function isEqual($d)
  92    {
  93      return $this->translations == $d->getTranslations();
  94    }
  95  }
  96  
  97  ?>


Generated: Tue Oct 14 04:47:40 2008 Cross-referenced by PHPXref 0.7