Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12a183a

Browse files
committed
Revert inlining the fallback messages in production that was added in 6eb5e73
Also add a test that shows where this would cause inconsistent behaviour of the getFallbackCatalogue() method.
1 parent b5da2ae commit 12a183a

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,45 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales(
196196
$this->assertEquals('bar', $translator->trans('bar'));
197197
}
198198

199+
public function testGetCatalogueBehavesConsistently()
200+
{
201+
/*
202+
* Create a translator that loads two catalogues for two different locales.
203+
* The catalogues contain distinct sets of messages.
204+
*/
205+
$translator = new Translator('a', null, $this->tmpDir);
206+
$translator->setFallbackLocales(array('b'));
207+
208+
$translator->addLoader('array', new ArrayLoader());
209+
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
210+
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
211+
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
212+
213+
$catalogue = $translator->getCatalogue('a');
214+
$this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message.
215+
216+
$fallback = $catalogue->getFallbackCatalogue();
217+
$this->assertTrue($fallback->defines('foo')); // "foo" is present in "a" and "b"
218+
219+
/*
220+
* Now, repeat the same test.
221+
* Behind the scenes, the cache is used. But that should not matter, right?
222+
*/
223+
$translator = new Translator('a', null, $this->tmpDir);
224+
$translator->setFallbackLocales(array('b'));
225+
226+
$translator->addLoader('array', new ArrayLoader());
227+
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
228+
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
229+
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
230+
231+
$catalogue = $translator->getCatalogue('a');
232+
$this->assertFalse($catalogue->defines('bar'));
233+
234+
$fallback = $catalogue->getFallbackCatalogue();
235+
$this->assertTrue($fallback->defines('foo'));
236+
}
237+
199238
protected function getCatalogue($locale, $messages)
200239
{
201240
$catalogue = new MessageCatalogue($locale);

src/Symfony/Component/Translation/Translator.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,6 @@ public function dumpCatalogue($locale, ConfigCacheInterface $cache)
420420

421421
private function getFallbackContent(MessageCatalogue $catalogue)
422422
{
423-
if (!$this->debug) {
424-
// merge all fallback catalogues messages into $catalogue
425-
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
426-
$messages = $catalogue->all();
427-
while ($fallbackCatalogue) {
428-
$messages = array_replace_recursive($fallbackCatalogue->all(), $messages);
429-
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
430-
}
431-
foreach ($messages as $domain => $domainMessages) {
432-
$catalogue->add($domainMessages, $domain);
433-
}
434-
435-
return '';
436-
}
437-
438423
$fallbackContent = '';
439424
$current = '';
440425
$replacementPattern = '/[^a-z0-9_]/i';

0 commit comments

Comments
 (0)