Skip to content

Commit

Permalink
[Translation] keep old array structure of resourcesFiles to avoid BC.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Mar 23, 2015
1 parent 1a4d7d7 commit aa70a94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
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
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
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
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 comments on commit aa70a94

Please sign in to comment.