From 2aa62df02973bc9ce2310361c828d8e7306ab343 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 26 Apr 2018 14:20:27 +0200 Subject: [PATCH] [Translator] Further postpone adding resource files --- .../FrameworkBundle/Translation/Translator.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 14cb2adecfe55..4aab26fc5e894 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -46,6 +46,8 @@ class Translator extends BaseTranslator implements WarmableInterface */ private $resources = array(); + private $resourceFiles; + /** * Constructor. * @@ -75,7 +77,7 @@ public function __construct(ContainerInterface $container, MessageFormatterInter $this->options = array_merge($this->options, $options); $this->resourceLocales = array_keys($this->options['resource_files']); - $this->addResourceFiles($this->options['resource_files']); + $this->resourceFiles = $this->options['resource_files']; parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug']); } @@ -103,6 +105,9 @@ public function warmUp($cacheDir) public function addResource($format, $resource, $locale, $domain = null) { + if ($this->resourceFiles) { + $this->addResourceFiles(); + } $this->resources[] = array($format, $resource, $locale, $domain); } @@ -117,6 +122,9 @@ protected function initializeCatalogue($locale) protected function initialize() { + if ($this->resourceFiles) { + $this->addResourceFiles(); + } foreach ($this->resources as $key => $params) { list($format, $resource, $locale, $domain) = $params; parent::addResource($format, $resource, $locale, $domain); @@ -130,8 +138,11 @@ protected function initialize() } } - private function addResourceFiles($filesByLocale) + private function addResourceFiles() { + $filesByLocale = $this->resourceFiles; + $this->resourceFiles = array(); + foreach ($filesByLocale as $locale => $files) { foreach ($files as $key => $file) { // filename is domain.locale.format