本文整理汇总了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'));
}
示例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']);
}
示例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;
}
示例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;
}