Skip to content

Commit

Permalink
minor #27063 [Translator] Further postpone adding resource files (nic…
Browse files Browse the repository at this point in the history
…olas-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
  • Loading branch information
nicolas-grekas committed Apr 29, 2018
2 parents ff19a04 + 2aa62df commit d843181
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Expand Up @@ -46,6 +46,8 @@ class Translator extends BaseTranslator implements WarmableInterface
*/
private $resources = array();

private $resourceFiles;

/**
* Constructor.
*
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit d843181

Please sign in to comment.