Skip to content

Commit 2de0b6f

Browse files
Merge branch '2.8' into 3.0
* 2.8: [Process] Fix transient tests for incremental outputs [Console] Add missing `@require` annotation in test Fix merge [appveyor] Fix failure reporting [#17634] move DebugBundle license file backport GlobTest from 2.7 branch Move licenses according to new best practices [FrameworkBundle] Remove unused code in test [2.3] Fixed an undefined variable in Glob::toRegex simplified a test fix container cache key generation [Form] fix option name in upgrade file [Form] fix option name in changelog [Translation] Add resources from fallback locale [DependencyInjection] enforce tags to have a name [YAML] Refine the return value of Yaml::parse() Conflicts: UPGRADE-2.8.md
2 parents 148e136 + b7b4eba commit 2de0b6f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Tests/TranslatorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,26 @@ public function testWhenAResourceHasNoRegisteredLoader()
273273
$translator->trans('foo');
274274
}
275275

276+
public function testFallbackCatalogueResources()
277+
{
278+
$translator = new Translator('en_GB', new MessageSelector());
279+
$translator->addLoader('yml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
280+
$translator->addResource('yml', __DIR__.'/fixtures/empty.yml', 'en_GB');
281+
$translator->addResource('yml', __DIR__.'/fixtures/resources.yml', 'en');
282+
283+
// force catalogue loading
284+
$this->assertEquals('bar', $translator->trans('foo', array()));
285+
286+
$resources = $translator->getCatalogue('en')->getResources();
287+
$this->assertCount(1, $resources);
288+
$this->assertContains( __DIR__.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'resources.yml', $resources);
289+
290+
$resources = $translator->getCatalogue('en_GB')->getResources();
291+
$this->assertCount(2, $resources);
292+
$this->assertContains( __DIR__.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'empty.yml', $resources);
293+
$this->assertContains( __DIR__.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'resources.yml', $resources);
294+
}
295+
276296
/**
277297
* @dataProvider getTransTests
278298
*/

Translator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ private function loadFallbackCatalogues($locale)
384384
}
385385

386386
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
387+
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
388+
$fallbackCatalogue->addResource($resource);
389+
}
387390
$current->addFallbackCatalogue($fallbackCatalogue);
388391
$current = $fallbackCatalogue;
389392
}

0 commit comments

Comments
 (0)