Skip to content

Commit 1251f0e

Browse files
committed
[FrameworkBundle][config] allow multiple fallback locales.
1 parent 51983d0 commit 1251f0e

File tree

8 files changed

+45
-7
lines changed

8 files changed

+45
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,13 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
364364
->arrayNode('translator')
365365
->info('translator configuration')
366366
->canBeEnabled()
367+
->fixXmlConfig('fallback')
367368
->children()
368-
->scalarNode('fallback')->defaultValue('en')->end()
369+
->arrayNode('fallbacks')
370+
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
371+
->prototype('scalar')->end()
372+
->defaultValue(array('en'))
373+
->end()
369374
->end()
370375
->end()
371376
->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
226226
'memcached' => 'Symfony\Component\HttpKernel\Profiler\MemcachedProfilerStorage',
227227
'redis' => 'Symfony\Component\HttpKernel\Profiler\RedisProfilerStorage',
228228
);
229-
list($class,) = explode(':', $config['dsn'], 2);
229+
list($class, ) = explode(':', $config['dsn'], 2);
230230
if (!isset($supported[$class])) {
231231
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
232232
}
@@ -534,10 +534,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
534534
// Use the "real" translator instead of the identity default
535535
$container->setAlias('translator', 'translator.default');
536536
$translator = $container->findDefinition('translator.default');
537-
if (!is_array($config['fallback'])) {
538-
$config['fallback'] = array($config['fallback']);
539-
}
540-
$translator->addMethodCall('setFallbackLocales', array($config['fallback']));
537+
$translator->addMethodCall('setFallbackLocales', array($config['fallbacks']));
541538

542539
// Discover translation directories
543540
$dirs = array();

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
</xsd:complexType>
126126

127127
<xsd:complexType name="translator">
128+
<xsd:sequence>
129+
<xsd:element name="fallback" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
130+
</xsd:sequence>
128131
<xsd:attribute name="enabled" type="xsd:boolean" />
129132
<xsd:attribute name="fallback" type="xsd:string" />
130133
</xsd:complexType>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected static function getBundleDefaultConfig()
115115
),
116116
'translator' => array(
117117
'enabled' => false,
118-
'fallback' => 'en',
118+
'fallbacks' => array('en'),
119119
),
120120
'validation' => array(
121121
'enabled' => false,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'translator' => array(
5+
'fallbacks' => array('en', 'fr'),
6+
),
7+
));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:translator enabled="true">
11+
<framework:fallback>en</framework:fallback>
12+
<framework:fallback>fr</framework:fallback>
13+
</framework:translator>
14+
</framework:config>
15+
</container>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
translator:
3+
fallbacks: [en, fr]

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ public function testTranslator()
206206
$this->assertEquals(array('fr'), $calls[0][1][0]);
207207
}
208208

209+
public function testTranslatorMultipleFullback()
210+
{
211+
$container = $this->createContainerFromFile('translator_fallbacks');
212+
213+
$calls = $container->getDefinition('translator.default')->getMethodCalls();
214+
$this->assertEquals(array('en', 'fr'), $calls[0][1][0]);
215+
}
216+
209217
/**
210218
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
211219
*/

0 commit comments

Comments
 (0)