Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41990b0

Browse filesBrowse files
committed
[Translation] Add resources from fallback locale
1 parent 6eda9ad commit 41990b0
Copy full SHA for 41990b0

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed

‎src/Symfony/Component/Translation/Tests/TranslatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/TranslatorTest.php
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ public function testWhenAResourceHasNoRegisteredLoader()
239239
$translator->trans('foo');
240240
}
241241

242+
public function testFallbackCatalogueResources()
243+
{
244+
$loaderClass = 'Symfony\\Component\\Translation\\Loader\\YamlFileLoader';
245+
$translator = new Translator('en_GB', new MessageSelector());
246+
$translator->addLoader('yml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
247+
$translator->addResource('yml', __DIR__.'/fixtures/empty.yml', 'en_GB');
248+
$translator->addResource('yml', __DIR__.'/fixtures/resources.yml', 'en');
249+
250+
// force catalogue loading
251+
$this->assertEquals('bar', $translator->trans('foo', array()));
252+
253+
$cataloguesProperty = new \ReflectionProperty($translator, 'catalogues');
254+
$cataloguesProperty->setAccessible(true);
255+
$catalogues = $cataloguesProperty->getValue($translator);
256+
257+
$resources = $catalogues['en']->getResources();
258+
$this->assertCount(1, $resources);
259+
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
260+
261+
$resources = $catalogues['en_GB']->getResources();
262+
$this->assertCount(2, $resources);
263+
$this->assertContains( __DIR__.'/fixtures/empty.yml', $resources);
264+
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
265+
}
266+
242267
/**
243268
* @dataProvider getTransTests
244269
*/

‎src/Symfony/Component/Translation/Translator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Translator.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ private function loadFallbackCatalogues($locale)
255255
}
256256

257257
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
258+
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
259+
$fallbackCatalogue->addResource($resource);
260+
}
258261
$current->addFallbackCatalogue($fallbackCatalogue);
259262
$current = $fallbackCatalogue;
260263
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.