Skip to content

Commit d843181

Browse files
minor #27063 [Translator] Further postpone adding resource files (nicolas-grekas)
This PR was merged into the 4.1-dev branch. Discussion ---------- [Translator] Further postpone adding resource files | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27010 | License | MIT | Doc PR | - Commits ------- 2aa62df [Translator] Further postpone adding resource files
2 parents ff19a04 + 2aa62df commit d843181

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Translator extends BaseTranslator implements WarmableInterface
4646
*/
4747
private $resources = array();
4848

49+
private $resourceFiles;
50+
4951
/**
5052
* Constructor.
5153
*
@@ -75,7 +77,7 @@ public function __construct(ContainerInterface $container, MessageFormatterInter
7577

7678
$this->options = array_merge($this->options, $options);
7779
$this->resourceLocales = array_keys($this->options['resource_files']);
78-
$this->addResourceFiles($this->options['resource_files']);
80+
$this->resourceFiles = $this->options['resource_files'];
7981

8082
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug']);
8183
}
@@ -103,6 +105,9 @@ public function warmUp($cacheDir)
103105

104106
public function addResource($format, $resource, $locale, $domain = null)
105107
{
108+
if ($this->resourceFiles) {
109+
$this->addResourceFiles();
110+
}
106111
$this->resources[] = array($format, $resource, $locale, $domain);
107112
}
108113

@@ -117,6 +122,9 @@ protected function initializeCatalogue($locale)
117122

118123
protected function initialize()
119124
{
125+
if ($this->resourceFiles) {
126+
$this->addResourceFiles();
127+
}
120128
foreach ($this->resources as $key => $params) {
121129
list($format, $resource, $locale, $domain) = $params;
122130
parent::addResource($format, $resource, $locale, $domain);
@@ -130,8 +138,11 @@ protected function initialize()
130138
}
131139
}
132140

133-
private function addResourceFiles($filesByLocale)
141+
private function addResourceFiles()
134142
{
143+
$filesByLocale = $this->resourceFiles;
144+
$this->resourceFiles = array();
145+
135146
foreach ($filesByLocale as $locale => $files) {
136147
foreach ($files as $key => $file) {
137148
// filename is domain.locale.format

0 commit comments

Comments
 (0)