8000 bug #20422 [Translation][fallback] add missing resources in parent ca… · symfony/symfony@b06c00e · GitHub
[go: up one dir, main page]

Skip to content

Commit b06c00e

Browse files
committed
bug #20422 [Translation][fallback] add missing resources in parent catalogues. (aitboudad)
This PR was merged into the 2.7 branch. Discussion ---------- [Translation][fallback] add missing resources in parent catalogues. | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20420 | License | MIT | Doc PR | ~ Commits ------- 27c91e5 [Translation][fallback] add missing resources in parent catalogues.
2 parents 94d9bfb + 27c91e5 commit b06c00e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Symfony/Component/Translation/MessageCatalogue.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
178178
if ($c->getLocale() === $catalogue->getLocale()) {
179179
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
180180
}
181+
182+
foreach ($catalogue->getResources() as $resource) {
183+
$c->addResource($resource);
184+
}
181185
} while ($c = $c->parent);
182186

183187
$catalogue->parent = $this;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,25 @@ public function testAddFallbackCatalogue()
110110
$r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
111111
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
112112

113-
$catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
113+
$r2 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
114+
$r2->expects($this->any())->method('__toString')->will($this->returnValue('r2'));
115+
116+
$catalogue = new MessageCatalogue('fr_FR', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
114117
$catalogue->addResource($r);
115118

116-
$catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1')));
119+
$catalogue1 = new MessageCatalogue('fr', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1')));
117120
$catalogue1->addResource($r1);
118121

122+
$catalogue2 = new MessageCatalogue('en');
123+
$catalogue2->addResource($r2);
124+
119125
$catalogue->addFallbackCatalogue($catalogue1);
126+
$catalogue1->addFallbackCatalogue($catalogue2);
120127

121128
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
122129
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
123130

124-
$this->assertEquals(array($r, $r1), $catalogue->getResources());
131+
$this->assertEquals(array($r, $r1, $r2), $catalogue->getResources());
125132
}
126133

127134
/**

0 commit comments

Comments
 (0)
0