Advertisement
Guest User

unzend.com_333

a guest
Oct 10th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.84 KB | None | 0 0
  1. <?php
  2. // Ioncube Decoder Unzend.Com Email unzend@gmail.com
  3. // http://www.unzend.com
  4. /**
  5.  * CGettextMessageSource class file.
  6.  *
  7.  * @author Qiang Xue <qiang.xue@gmail.com>
  8.  * @link http://www.yiiframework.com/
  9.  * @copyright 2008-2013 Yii Software LLC
  10.  * @license http://www.yiiframework.com/license/
  11.  */
  12.  
  13. /**
  14.  * CGettextMessageSource represents a message source that is based on GNU Gettext.
  15.  *
  16.  * Each CGettextMessageSource instance represents the message tranlations
  17.  * for a single domain. And each message category represents a message context
  18.  * in Gettext. Translated messages are stored as either a MO or PO file,
  19.  * depending on the {@link useMoFile} property value.
  20.  *
  21.  * All translations are saved under the {@link basePath} directory.
  22.  * Translations in one language are kept as MO or PO files under an individual
  23.  * subdirectory whose name is the language ID. The file name is specified via
  24.  * {@link catalog} property, which defaults to 'messages'.
  25.  *
  26.  * @author Qiang Xue <qiang.xue@gmail.com>
  27.  * @package system.i18n
  28.  * @since 1.0
  29.  */
  30. class CGettextMessageSource extends CMessageSource
  31. {
  32.     const CACHE_KEY_PREFIX='Yii.CGettextMessageSource.';
  33.     const MO_FILE_EXT='.mo';
  34.     const PO_FILE_EXT='.po';
  35.  
  36.     /**
  37.      * @var integer the time in seconds that the messages can remain valid in cache.
  38.      * Defaults to 0, meaning the caching is disabled.
  39.      */
  40.     public $cachingDuration=0;
  41.     /**
  42.      * @var string the ID of the cache application component that is used to cache the messages.
  43.      * Defaults to 'cache' which refers to the primary cache application component.
  44.      * Set this property to false if you want to disable caching the messages.
  45.      */
  46.     public $cacheID='cache';
  47.     /**
  48.      * @var string the base path for all translated messages. Defaults to null, meaning
  49.      * the "messages" subdirectory of the application directory (e.g. "protected/messages").
  50.      */
  51.     public $basePath;
  52.     /**
  53.      * @var boolean whether to load messages from MO files. Defaults to true.
  54.      * If false, messages will be loaded from PO files.
  55.      */
  56.     public $useMoFile=true;
  57.     /**
  58.      * @var boolean whether to use Big Endian to read and write MO files.
  59.      * Defaults to false. This property is only used when {@link useMoFile} is true.
  60.      */
  61.     public $useBigEndian=false;
  62.     /**
  63.      * @var string the message catalog name. This is the name of the message file (without extension)
  64.      * that stores the translated messages. Defaults to 'messages'.
  65.      */
  66.     public $catalog='messages';
  67.  
  68.     /**
  69.      * Initializes the application component.
  70.      * This method overrides the parent implementation by preprocessing
  71.      * the user request data.
  72.      */
  73.     public function init()
  74.     {
  75.         parent::init();
  76.         if($this->basePath===null)
  77.             $this->basePath=Yii::getPathOfAlias('application.messages');
  78.     }
  79.  
  80.     /**
  81.      * Loads the message translation for the specified language and category.
  82.      * @param string $category the message category
  83.      * @param string $language the target language
  84.      * @return array the loaded messages
  85.      */
  86.     protected function loadMessages($category, $language)
  87.     {
  88.         $messageFile=$this->basePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $this->catalog;
  89.         if($this->useMoFile)
  90.             $messageFile.=self::MO_FILE_EXT;
  91.         else
  92.             $messageFile.=self::PO_FILE_EXT;
  93.  
  94.         if ($this->cachingDuration > 0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null)
  95.         {
  96.             $key = self::CACHE_KEY_PREFIX . $messageFile . "." . $category;
  97.             if (($data=$cache->get($key)) !== false)
  98.                 return unserialize($data);
  99.         }
  100.  
  101.         if (is_file($messageFile))
  102.         {
  103.             if($this->useMoFile)
  104.                 $file=new CGettextMoFile($this->useBigEndian);
  105.             else
  106.                 $file=new CGettextPoFile();
  107.             $messages=$file->load($messageFile,$category);
  108.             if(isset($cache))
  109.             {
  110.                 $dependency=new CFileCacheDependency($messageFile);
  111.                 $cache->set($key,serialize($messages),$this->cachingDuration,$dependency);
  112.             }
  113.             return $messages;
  114.         }
  115.         else
  116.             return array();
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement