public function testNonInitException3() { $currentDir = dirname(__FILE__); $backend = new ezcTranslationCacheBackend($this->cacheObj); $backend->initWriter('nb-no'); $backend->deinitWriter(); try { $backend->deinitWriter(); } catch (ezcTranslationWriterNotInitializedException $e) { self::assertEquals("The writer is not initialized with the initWriter() method.", $e->getMessage()); } }
private function updateCache() { try { $sys = erLhcoreClassSystem::instance()->SiteDir; $reader = new ezcTranslationTsBackend($sys . '/translations/' . $this->languageCode); $reader->setOptions(array('format' => 'translation.ts')); $reader->initReader($this->languageCode); $cacheObj = new ezcCacheStorageFileArray($sys . '/cache/translations'); $writer = new ezcTranslationCacheBackend($cacheObj); $writer->initWriter($this->languageCode); // Load extensions translations $extensions = erConfigClassLhConfig::getInstance()->getSetting('site', 'extensions'); $contextDataArray = array(); foreach ($extensions as $ext) { $trsDir = $sys . 'extension/' . $ext . '/translations/' . $this->languageCode . '/translation.ts'; if (file_exists($trsDir)) { $readerExtension = new ezcTranslationTsBackend($sys . '/extension/' . $ext . '/translations/' . $this->languageCode); $readerExtension->setOptions(array('format' => 'translation.ts')); $readerExtension->initReader($this->languageCode); foreach ($readerExtension as $contextName => $contextData) { if (isset($contextDataArray[$contextName])) { // Perhaps few extensions have same content? $contextDataArray[$contextName] = array_merge($contextDataArray[$contextName], $contextData); } else { $contextDataArray[$contextName] = $contextData; } } $readerExtension->deInitReader(); } } // Store translations foreach ($reader as $contextName => $contextData) { if (isset($contextDataArray[$contextName])) { $contextData = array_merge($contextData, $contextDataArray[$contextName]); unset($contextDataArray[$contextName]); } $writer->storeContext($contextName, $contextData); } // Store unique extension context foreach ($contextDataArray as $contextName => $contextData) { $writer->storeContext($contextName, $contextData); } $reader->deInitReader(); unset($contextDataArray); $writer->deInitWriter(); } catch (Exception $e) { // Sometimes write fails, so ignore it } }
<?php require_once 'tutorial_autoload.php'; $reader = new ezcTranslationTsBackend(dirname(__FILE__) . '/translations'); $reader->setOptions(array('format' => 'translation-[LOCALE].xml')); $reader->initReader('nb_NO'); $cacheObj = new ezcCacheStorageFileArray(dirname(__FILE__) . '/translations-cache'); $writer = new ezcTranslationCacheBackend($cacheObj); $writer->initWriter('nb_NO'); foreach ($reader as $contextName => $contextData) { $writer->storeContext($contextName, $contextData); } $reader->deInitReader(); $writer->deInitWriter();