Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Jump to cache-storing instead of returning #2322

Closed
wants to merge 3 commits into from

2 participants

@DASPRiD
Collaborator

No description provided.

@weierophinney

Test, please -- because clearly the tests didn't detect the change between rc6 and rc7.

@weierophinney weierophinney reopened this
@weierophinney

@DASPRiD bump.

@DASPRiD
Collaborator

@weierophinney There you go, fresh unit tests.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2322'
Close #2322
1f68c7d
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2322' into develop
Forward port #2322
1863e39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 library/Zend/I18n/Translator/Translator.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]);
}
View
18 tests/ZendTest/I18n/Translator/TranslatorTest.php
@@ -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()
Something went wrong with that request. Please try again.