From e36f1a70e19ff12caa208ff75087a76b7a2ffac1 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Sat, 21 Mar 2015 21:30:03 +0000 Subject: [PATCH] [FrameworkBundle][Translation][debug mode] refresh cache when resources is changed. --- .../Tests/Translation/TranslatorTest.php | 6 ++++++ .../FrameworkBundle/Translation/Translator.php | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php index b3df0339b32b..1da8faea5433 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php @@ -122,6 +122,12 @@ public function testLoadRessourcesWithCaching() $translator->setLocale('fr'); $this->assertEquals('répertoire', $translator->trans('folder')); + + // refresh cache when resources is changed in debug mode. + $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true), array(), 'yml'); + $translator->setLocale('fr'); + + $this->assertEquals('folder', $translator->trans('folder')); } public function testLoadRessourcesWithoutCaching() diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 8e9843931d50..3d0f2b04e19f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -63,6 +63,18 @@ public function __construct(ContainerInterface $container, MessageSelector $sele parent::__construct(null, $selector, $this->options['cache_dir'], $this->options['debug']); } + /** + * {@inheritdoc} + */ + protected function loadCatalogue($locale) + { + if (null !== $this->options['cache_dir'] && $this->options['debug']) { + $this->loadResources($locale); + } + + parent::loadCatalogue($locale); + } + /** * {@inheritdoc} */