Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 #23057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix resource loading order inconsistency reported in #23034
  • Loading branch information
mpdude committed Jun 8, 2017
commit ddc7a61d2624312b6793e64dac44380b9f4653a9
22 changes: 21 additions & 1 deletion 22 src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class Translator extends BaseTranslator implements WarmableInterface
*/
private $resourceLocales;

/**
* Holds parameters from addResource() calls so we can add these resources
* after the ones passed in the resource_files option (which are added
* lazily in loadResources() as well).
*
* @var array
*/
private $otherResources = array();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, using this array to collect addResource() calls and actually execute them after the resource_files is ugly, but we don't have access to the private \Symfony\Component\Translation\Translator::$resources field so that we could "unshift" the resource_files in front of it in loadResources.


/**
* Constructor.
*
Expand Down Expand Up @@ -93,6 +102,11 @@ public function warmUp($cacheDir)
}
}

public function addResource($format, $resource, $locale, $domain = null)
{
$this->otherResources[] = array($format, $resource, $locale, $domain);
}

/**
* {@inheritdoc}
*/
Expand All @@ -118,9 +132,15 @@ private function loadResources()
foreach ($files as $key => $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
parent::addResource($format, $file, $locale, $domain);
unset($this->options['resource_files'][$locale][$key]);
}
}

foreach ($this->otherResources as $key => $params) {
list($format, $resource, $locale, $domain) = $params;
parent::addResource($format, $resource, $locale, $domain);
unset($this->otherResources[$key]);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.