[Translation] fix dumping catalogues cache
This commit is contained in:
parent
d9f87b6f58
commit
4aab6e72c1
@ -66,13 +66,17 @@ class TranslatorCacheTest extends TestCase
|
|||||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||||
$translator->addLoader($format, new ArrayLoader());
|
$translator->addLoader($format, new ArrayLoader());
|
||||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||||
|
$translator->addResource($format, array($msgid.'+intl' => 'OK'), $locale, 'messages+intl-icu');
|
||||||
$translator->trans($msgid);
|
$translator->trans($msgid);
|
||||||
|
$translator->trans($msgid.'+intl', array(), 'messages+intl-icu');
|
||||||
|
|
||||||
// Try again and see we get a valid result whilst no loader can be used
|
// Try again and see we get a valid result whilst no loader can be used
|
||||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||||
$translator->addLoader($format, $this->createFailingLoader());
|
$translator->addLoader($format, $this->createFailingLoader());
|
||||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||||
|
$translator->addResource($format, array($msgid.'+intl' => 'OK'), $locale, 'messages+intl-icu');
|
||||||
$this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
|
$this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
|
||||||
|
$this->assertEquals('OK', $translator->trans($msgid.'+intl', array(), 'messages+intl-icu'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
|
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
|
||||||
@ -212,6 +216,7 @@ class TranslatorCacheTest extends TestCase
|
|||||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||||
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
||||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||||
|
$translator->addResource('array', array('baz' => 'baz (b)'), 'b', 'messages+intl-icu');
|
||||||
|
|
||||||
$catalogue = $translator->getCatalogue('a');
|
$catalogue = $translator->getCatalogue('a');
|
||||||
$this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message.
|
$this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message.
|
||||||
@ -230,12 +235,14 @@ class TranslatorCacheTest extends TestCase
|
|||||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||||
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
||||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||||
|
$translator->addResource('array', array('baz' => 'baz (b)'), 'b', 'messages+intl-icu');
|
||||||
|
|
||||||
$catalogue = $translator->getCatalogue('a');
|
$catalogue = $translator->getCatalogue('a');
|
||||||
$this->assertFalse($catalogue->defines('bar'));
|
$this->assertFalse($catalogue->defines('bar'));
|
||||||
|
|
||||||
$fallback = $catalogue->getFallbackCatalogue();
|
$fallback = $catalogue->getFallbackCatalogue();
|
||||||
$this->assertTrue($fallback->defines('foo'));
|
$this->assertTrue($fallback->defines('foo'));
|
||||||
|
$this->assertTrue($fallback->defines('baz', 'messages+intl-icu'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
|
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
|
||||||
|
@ -353,7 +353,7 @@ return \$catalogue;
|
|||||||
EOF
|
EOF
|
||||||
,
|
,
|
||||||
$locale,
|
$locale,
|
||||||
var_export($this->catalogues[$locale]->all(), true),
|
var_export($this->getAllMessages($this->catalogues[$locale]), true),
|
||||||
$fallbackContent
|
$fallbackContent
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ EOF
|
|||||||
,
|
,
|
||||||
$fallbackSuffix,
|
$fallbackSuffix,
|
||||||
$fallback,
|
$fallback,
|
||||||
var_export($fallbackCatalogue->all(), true),
|
var_export($this->getAllMessages($fallbackCatalogue), true),
|
||||||
$currentSuffix,
|
$currentSuffix,
|
||||||
$fallbackSuffix
|
$fallbackSuffix
|
||||||
);
|
);
|
||||||
@ -418,7 +418,7 @@ EOF
|
|||||||
$this->initializeCatalogue($fallback);
|
$this->initializeCatalogue($fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
$fallbackCatalogue = new MessageCatalogue($fallback, $this->getAllMessages($this->catalogues[$fallback]));
|
||||||
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
|
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
|
||||||
$fallbackCatalogue->addResource($resource);
|
$fallbackCatalogue->addResource($resource);
|
||||||
}
|
}
|
||||||
@ -487,4 +487,21 @@ EOF
|
|||||||
|
|
||||||
return $this->configCacheFactory;
|
return $this->configCacheFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getAllMessages(MessageCatalogueInterface $catalogue): array
|
||||||
|
{
|
||||||
|
$allMessages = array();
|
||||||
|
|
||||||
|
foreach ($catalogue->all() as $domain => $messages) {
|
||||||
|
if ($intlMessages = $catalogue->all($domain.MessageCatalogue::INTL_DOMAIN_SUFFIX)) {
|
||||||
|
$allMessages[$domain.MessageCatalogue::INTL_DOMAIN_SUFFIX] = $intlMessages;
|
||||||
|
$messages = array_diff_key($messages, $intlMessages);
|
||||||
|
}
|
||||||
|
if ($messages) {
|
||||||
|
$allMessages[$domain] = $messages;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $allMessages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user