minor #14022 [Translation] keep old array structure of resourcesFiles to avoid BC. (aitboudad)

This PR was merged into the 2.7 branch.

Discussion
----------

[Translation] keep old array structure of resourcesFiles to avoid BC.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets  | #13897
| Tests pass?   | yes
| License       | MIT

Commits
-------

aa70a94 [Translation] keep old array structure of resourcesFiles to avoid BC.
This commit is contained in:
Fabien Potencier 2015-03-24 08:57:42 +01:00
commit 2f399017b2
4 changed files with 13 additions and 35 deletions

View File

@ -700,11 +700,7 @@ class FrameworkExtension extends Extension
foreach ($finder as $file) {
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
if (!isset($files[$locale])) {
$files[$locale] = array();
}
$files[$locale][] = (string) $file;
$files[] = (string) $file;
}
$translator->replaceArgument(4, $files);

View File

@ -225,7 +225,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
$resources = $container->getDefinition('translator.default')->getArgument(4);
$files = array_map(function ($resource) { return realpath($resource); }, $resources['en']);
$files = array_map(function ($resource) { return realpath($resource); }, $resources);
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
$this->assertContains(
strtr(dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', DIRECTORY_SEPARATOR),

View File

@ -106,9 +106,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
{
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
$resourceFiles = array(
'fr' => array(
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
),
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
);
// prime the cache
@ -134,9 +132,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
{
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
$resourceFiles = array(
'fr' => array(
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
),
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
);
$translator = $this->getTranslator($loader, array(), $resourceFiles, 'yml');

View File

@ -59,20 +59,11 @@ class Translator extends BaseTranslator
}
$this->options = array_merge($this->options, $options);
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);
$this->loadResources();
}
parent::loadCatalogue($locale);
parent::__construct(null, $selector, $this->options['cache_dir'], $this->options['debug']);
}
/**
@ -81,12 +72,12 @@ class Translator extends BaseTranslator
protected function initializeCatalogue($locale)
{
$this->initialize();
$this->loadResources($locale);
parent::initializeCatalogue($locale);
}
protected function initialize()
{
$this->loadResources();
foreach ($this->loaderIds as $id => $aliases) {
foreach ($aliases as $alias) {
$this->addLoader($alias, $this->container->get($id));
@ -94,18 +85,13 @@ class Translator extends BaseTranslator
}
}
private function loadResources($locale)
private function loadResources()
{
$locales = array_merge(array($locale), $this->computeFallbackLocales($locale));
foreach ($locales as $locale) {
if (isset($this->resourceFiles[$locale])) {
foreach ($this->resourceFiles[$locale] as $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
}
unset($this->resourceFiles[$locale]);
}
foreach ($this->resourceFiles as $key => $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
unset($this->resourceFiles[$key]);
}
}
}