8000 [Translation] keep old array structure of resourcesFiles to avoid BC. by aitboudad · Pull Request #14022 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 1 commit into from
Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function testTranslator()
$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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ public function testLoadRessourcesWithCaching()
{
$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
Expand All @@ -134,9 +132,7 @@ public function testLoadRessourcesWithoutCaching()
{
$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');
Expand Down
32 changes: 9 additions & 23 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,11 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
}

$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']);
}

/**
Expand All @@ -81,31 +72,26 @@ protected function loadCatalogue($locale)
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));
}
}
}

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]);
}
}
}
0