當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Translator::setCache方法代碼示例

本文整理匯總了PHP中Zend\I18n\Translator\Translator::setCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP Translator::setCache方法的具體用法?PHP Translator::setCache怎麽用?PHP Translator::setCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\I18n\Translator\Translator的用法示例。


在下文中一共展示了Translator::setCache方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTranslateWithCache

 public function testTranslateWithCache()
 {
     $cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
     $this->translator->setCache($cache);
     $loader = new TestLoader();
     $loader->textDomain = new TextDomain(array('foo' => 'bar'));
     $this->translator->getPluginManager()->setService('test', $loader);
     $this->translator->addTranslationFile('test', null);
     $this->assertEquals('bar', $this->translator->translate('foo'));
 }
開發者ID:haoyanfei,項目名稱:zf2,代碼行數:10,代碼來源:TranslatorTest.php

示例2: testTranslationsAreStoredInCache

 public function testTranslationsAreStoredInCache()
 {
     $cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
     $this->translator->setCache($cache);
     $loader = new TestLoader();
     $loader->textDomain = new TextDomain(array('foo' => 'bar'));
     $this->translator->getPluginManager()->setService('test', $loader);
     $this->translator->addTranslationFile('test', null);
     $this->assertEquals('bar', $this->translator->translate('foo'));
     $item = $cache->getItem('Zend_I18n_Translator_Messages_' . md5('default' . 'en_EN'));
     $this->assertInstanceOf('Zend\\I18n\\Translator\\TextDomain', $item);
     $this->assertEquals('bar', $item['foo']);
 }
開發者ID:nieldm,項目名稱:zf2,代碼行數:13,代碼來源:TranslatorTest.php

示例3: init

 public function init()
 {
     $this->app->configs->setDefaultConfig($this->id, new TranslatorConfig(), $this);
     $this->translator = $translator = new Translator();
     /** @var TranslatorConfig $config */
     $this->moduleConfig = $config = $this->app->configs->getConfig($this->id);
     if (!$this->app->getConfig()->developmentMode) {
         $c = new Filesystem();
         $o = new FilesystemOptions();
         $o->setCacheDir($this->app->cacheStorage->createStorage($this->id));
         $c->setOptions($o);
         $c->addPlugin(new Serializer());
         $translator->setCache($c);
     }
     $translator->setLocale($config->defaultLanguage);
     $folder = $this->app->parseUri($config->translationsDirectory);
     foreach ($config->contexts as $context => $file) {
         if (is_int($context)) {
             $context = $file;
             $file .= '.mo';
         }
         $translator->addTranslationFilePattern('gettext', $folder, '%s/' . $file, $context);
     }
     $this->translator = $translator;
 }
開發者ID:cyantree,項目名稱:grout-translator-module,代碼行數:25,代碼來源:TranslatorModule.php

示例4: createTranslatorAdapter

 /**
  * {@inheritDoc}
  */
 public function createTranslatorAdapter($locale)
 {
     $cache = new ZendCacheDriver('cache/expensive');
     $t = new Translator();
     $t->setCache($cache);
     $adapter = new TranslatorAdapter($t);
     $adapter->setLocale($locale);
     if (isset($this->translationLoaderRepository)) {
         foreach ($this->translationLoaderRepository->getTranslationLoaders() as $key => $loader) {
             $loader->loadTranslations($adapter);
         }
     }
     return $adapter;
 }
開發者ID:ppiedaderawnet,項目名稱:concrete5,代碼行數:17,代碼來源:TranslatorAdapterFactory.php


注:本文中的Zend\I18n\Translator\Translator::setCache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。