本文整理匯總了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;
}