当前位置: 首页>>代码示例>>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;未经允许,请勿转载。