Skip to content

Commit 85c1ed7

Browse files
Merge branch '4.3' into 4.4
* 4.3: [DI] Dont cache classes with missing parents [HttpClient] Fix a crash when calling CurlHttpClient::__destruct() [Validator] Add the missing translations for the Hebrew (\"he\") locale and fix 2 typos [FrameworkBundle][Translation] Invalidate cached catalogues when the scanned directories change
2 parents d4b5173 + de30765 commit 85c1ed7

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: bar

Tests/Translation/TranslatorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Config\Resource\FileExistenceResource;
1919
use Symfony\Component\Filesystem\Filesystem;
2020
use Symfony\Component\Translation\Formatter\MessageFormatter;
21+
use Symfony\Component\Translation\Loader\YamlFileLoader;
2122
use Symfony\Component\Translation\MessageCatalogue;
2223

2324
class TranslatorTest extends TestCase
@@ -244,6 +245,41 @@ public function testCatalogResourcesAreAddedForScannedDirectories()
244245
$this->assertEquals(new FileExistenceResource('/tmp/I/sure/hope/this/does/not/exist'), $resources[2]);
245246
}
246247

248+
public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
249+
{
250+
/** @var Translator $translator */
251+
$translator = $this->getTranslator(new YamlFileLoader(), [
252+
'cache_dir' => $this->tmpDir,
253+
'resource_files' => [
254+
'fr' => [
255+
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
256+
],
257+
],
258+
'scanned_directories' => [
259+
__DIR__.'/../Fixtures/Resources/translations/',
260+
],
261+
], 'yml');
262+
263+
// Cached catalogue is dumped
264+
$this->assertSame('répertoire', $translator->trans('folder', [], 'messages', 'fr'));
265+
266+
$translator = $this->getTranslator(new YamlFileLoader(), [
267+
'cache_dir' => $this->tmpDir,
268+
'resource_files' => [
269+
'fr' => [
270+
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
271+
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
272+
],
273+
],
274+
'scanned_directories' => [
275+
__DIR__.'/../Fixtures/Resources/translations/',
276+
__DIR__.'/../Fixtures/Resources/translations2/',
277+
],
278+
], 'yml');
279+
280+
$this->assertSame('bar', $translator->trans('foo', [], 'ccc', 'fr'));
281+
}
282+
247283
protected function getCatalogue($locale, $messages, $resources = [])
248284
{
249285
$catalogue = new MessageCatalogue($locale);

Translation/Translator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function __construct(ContainerInterface $container, MessageFormatterInter
8282
$this->resourceFiles = $this->options['resource_files'];
8383
$this->scannedDirectories = $this->options['scanned_directories'];
8484

85-
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug']);
85+
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], [
86+
'scanned_directories' => $this->scannedDirectories,
87+
]);
8688
}
8789

8890
/**

0 commit comments

Comments
 (0)