Permalink
Browse files

Merge branch 'hotfix/2322' into develop

Forward port #2322
  • Loading branch information...
2 parents b5f50ba + 2b6105f commit fe1bcc6c86e9f97d76a15cb0cbaafeb23d66680a @weierophinney weierophinney committed Sep 20, 2012
Showing with 22 additions and 5 deletions.
  1. +5 −4 library/Zend/I18n/Translator/Translator.php
  2. +17 −1 tests/ZendTest/I18n/Translator/TranslatorTest.php
@@ -515,7 +515,7 @@ protected function loadMessages($textDomain, $locale)
}
$this->messages[$textDomain][$locale] = $loader->load($locale, $textDomain);
- return;
+ goto cache;
}
}
@@ -532,12 +532,12 @@ protected function loadMessages($textDomain, $locale)
}
$this->messages[$textDomain][$locale] = $loader->load($locale, $filename);
- return;
+ goto cache;
}
}
}
- // Load concrete files, may override those loaded from patterns
+ // Try to load from concrete files
foreach (array($locale, '*') as $currentLocale) {
if (!isset($this->files[$textDomain][$currentLocale])) {
continue;
@@ -553,10 +553,11 @@ protected function loadMessages($textDomain, $locale)
$this->messages[$textDomain][$locale] = $loader->load($locale, $file['filename']);
unset($this->files[$textDomain][$currentLocale]);
- return;
+ goto cache;
}
// Cache the loaded text domain
+ cache:
if ($cache !== null) {
$cache->setItem($cacheId, $this->messages[$textDomain][$locale]);
}
@@ -112,8 +112,20 @@ public function testTranslate()
$this->assertEquals('bar', $this->translator->translate('foo'));
}
+ public function testTranslationsLoadedFromCache()
+ {
+ $cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
+ $this->translator->setCache($cache);
+
+ $cache->addItem(
+ 'Zend_I18n_Translator_Messages_' . md5('default' . 'en_EN'),
+ new TextDomain(array('foo' => 'bar'))
+ );
- public function testTranslateWithCache()
+ $this->assertEquals('bar', $this->translator->translate('foo'));
+ }
+
+ public function testTranslationsAreStoredInCache()
{
$cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
$this->translator->setCache($cache);
@@ -124,6 +136,10 @@ public function testTranslateWithCache()
$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 testTranslatePlurals()

0 comments on commit fe1bcc6

Please sign in to comment.