Skip to content

Commit e24514a

Browse files
committed
minor #14011 [Translation][debug mode] refresh cache when resources is changed. (aitboudad)
This PR was merged into the 2.7 branch. Discussion ---------- [Translation][debug mode] refresh cache when resources is changed. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | #13897 | Tests pass? | yes | License | MIT Commits ------- e36f1a7 [FrameworkBundle][Translation][debug mode] refresh cache when resources is changed.
2 parents d906509 + 12ad3f3 commit e24514a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Tests/Translation/TranslatorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ public function testLoadRessourcesWithCaching()
122122
$translator->setLocale('fr');
123123

124124
$this->assertEquals('répertoire', $translator->trans('folder'));
125+
126+
// refresh cache when resources is changed in debug mode.
127+
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true), array(), 'yml');
128+
$translator->setLocale('fr');
129+
130+
$this->assertEquals('folder', $translator->trans('folder'));
125131
}
126132

127133
public function testLoadRessourcesWithoutCaching()

Translation/Translator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
6363
parent::__construct(null, $selector, $this->options['cache_dir'], $this->options['debug']);
6464
}
6565

66+
/**
67+
* {@inheritdoc}
68+
*/
69+
protected function loadCatalogue($locale)
70+
{
71+
if (null !== $this->options['cache_dir'] && $this->options['debug']) {
72+
$this->loadResources($locale);
73+
}
74+
75+
parent::loadCatalogue($locale);
76+
}
77+
6678
/**
6779
* {@inheritdoc}
6880
*/

0 commit comments

Comments
 (0)