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')); }
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']); }
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; }
/** * {@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; }