示例#1
0
 protected function _initTranslate()
 {
     $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/gasestema.ini");
     $resource = new Zend_Application_Resource_Translate(array('adapter' => 'gettext', 'locale' => $config->locale, 'data' => APPLICATION_PATH . "/translations/{$config->locale}.mo", 'options' => array('disableNotices' => true)));
     $resource->setBootstrap($this);
     return $resource->init();
 }
示例#2
0
 /**
  * Retrieve translation configuration options.
  * 
  * @return string
  */
 private function _setTranslate($locale, $cache)
 {
     $options = array('bootstrap' => $this->getBootstrap(), 'locale' => $locale, 'localeName' => $locale, 'adapter' => 'gettext', 'disableNotices' => true);
     if ($cache) {
         $options['cache'] = $cache;
     }
     $translatePath = LANGUAGES_DIR . "/{$locale}.mo";
     if (is_readable($translatePath)) {
         $options['content'] = $translatePath;
     } else {
         $options['content'] = '';
     }
     $translateResource = new Zend_Application_Resource_Translate($options);
     $translateResource->getTranslate();
 }
示例#3
0
 /**
  * Retrieve translate object
  *
  * @throws Zend_Application_Resource_Exception if registry key was used
  *          already but is no instance of Zend_Translate
  * @return Zend_Translate
  */
 public function getTranslate()
 {
     if (null === $this->_translate) {
         $this->buildLog();
         // retrieve cache if requested
         if (isset($this->_options['cacheEnabled']) && $this->_options['cacheEnabled']) {
             // check for cachemanager in bootstrap
             if (!$this->getBootstrap()->hasPluginResource('cachemanager')) {
                 throw new Zend_Application_Resource_Exception("You must configure the cachemanager with " . "the key {$this->getCacheKey()}");
             }
             // bootstrap the cachemanager and retrieve it
             /** @var $cacheManager Zend_Cache_Manager */
             $cacheManager = $this->getBootstrap()->bootstrap('cachemanager')->getResource('cachemanager');
             // check for the given key
             if (!$cacheManager->hasCache($this->getCacheKey())) {
                 throw new Zend_Application_Resource_Exception("You must configure the cachemanager with " . "the key {$this->getCacheKey()}");
             }
             // set cache for translator
             Zend_Translate_Adapter::setCache($cacheManager->getCache($this->getCacheKey()));
         }
         // fetch translate object into local variable
         $this->_translate = parent::getTranslate();
     }
     return $this->_translate;
 }
示例#4
0
 public function init()
 {
     $options = $this->getOptions();
     //reset content options
     if (isset($options['locale']) && isset($options['content']) && isset($options['fileExt'])) {
         //get locale data
         $session = new Zend_Session_Namespace('RFLib');
         if ($session->locale) {
             $locale = $session->locale;
         } else {
             $locale = $options['locale'];
         }
         $options['content'] = $options['content'] . DS . $locale . $options['fileExt'];
     }
     $this->setOptions($options);
     parent::init();
 }
示例#5
0
 public function init()
 {
     parent::init();
     $modules = Zend_Registry::get('modules');
     foreach ($modules as &$path) {
         if (is_dir($path . DS . 'Locales')) {
             $files = glob($path . DS . 'Locales' . DS . '*.*');
             if (sizeof($files)) {
                 foreach ($files as $file) {
                     //$name = basename($file);
                     //list($locale, $extension) = explode('.', $name);
                     $this->_translate->addTranslation(array('content' => $file, 'locale' => 'auto'));
                 }
             }
         }
     }
 }
示例#6
0
 /**
  * @group GH-103
  */
 public function testLogFactory()
 {
     $options = $this->_translationOptions;
     $options['log'][0] = new Zend_Log_Writer_Mock();
     $options['logUntranslated'] = true;
     $options['locale'] = 'en';
     $resource = new Zend_Application_Resource_Translate($options);
     $resource->setBootstrap($this->bootstrap);
     $resource->init()->translate('untranslated');
     $event = current($options['log'][0]->events);
     $this->assertTrue(is_array($event));
     $this->assertTrue(array_key_exists('message', $event));
     $this->assertEquals("Untranslated message within 'en': untranslated", $event['message']);
 }
示例#7
0
 /**
  * @group ZF-10352
  * @expectedException Zend_Application_Resource_Exception
  */
 public function testToUseTheTwoKeysContentAndDataShouldThrowsException()
 {
     $options = array('adapter' => 'array', 'content' => array('m1' => 'message1', 'm2' => 'message2'), 'data' => array('m3' => 'message3', 'm4' => 'message4'), 'locale' => 'auto');
     $resource = new Zend_Application_Resource_Translate($options);
     $translator = $resource->init();
 }
示例#8
0
 /**
  * @group ZF-7352
  */
 public function testTranslationIsAddedIfRegistryKeyExistsAlready()
 {
     $options1 = array('foo' => 'bar');
     $options2 = array_merge_recursive($this->_translationOptions, array('data' => array('message4' => 'bericht4')));
     $translate = new Zend_Translate(Zend_Translate::AN_ARRAY, $options1);
     Zend_Registry::set('Zend_Translate', $translate);
     $resource = new Zend_Application_Resource_Translate($options2);
     $this->assertTrue($translate === $resource->getTranslate());
     $this->assertEquals('bar', $translate->translate('foo'));
     $this->assertEquals('bericht4', $translate->translate('message4'));
     $this->assertEquals('shouldNotExist', $translate->translate('shouldNotExist'));
 }
示例#9
0
 protected function _initTranslate()
 {
     $options = Zend_Json::decode(Tri_Config::get('translate'));
     $resource = new Zend_Application_Resource_Translate($options);
     $resource->init();
 }