Skip to content

Commit baae750

Browse files
committed
[FrameworkBundle][Translation] allow register custom resources paths.
1 parent 862bdf1 commit baae750

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,17 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
575575
->info('translator configuration')
576576
->canBeEnabled()
577577
->fixXmlConfig('fallback')
578+
->fixXmlConfig('path')
578579
->children()
579580
->arrayNode('fallbacks')
580581
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
581582
->prototype('scalar')->end()
582583
->defaultValue(array('en'))
583584
->end()
585+
->arrayNode('paths')
586+
->defaultValue(array())
587+
->prototype('scalar')->end()
588+
->end()
584589
->booleanNode('logging')->defaultValue($this->debug)->end()
585590
->end()
586591
->end()

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,15 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
661661

662662
// Discover translation directories
663663
$dirs = array();
664+
665+
foreach ($config['paths'] as $path) {
666+
if (!is_dir($path)) {
667+
throw new \InvalidArgumentException(sprintf('The "%s" translation path does not exist.', $path));
668+
}
669+
670+
$dirs[] = $path;
671+
}
672+
664673
if (class_exists('Symfony\Component\Validator\Validation')) {
665674
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
666675

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<xsd:complexType name="translator">
184184
<xsd:sequence>
185185
<xsd:element name="fallback" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
186+
<xsd:element name="path" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
186187
</xsd:sequence>
187188
<xsd:attribute name="enabled" type="xsd:boolean" />
188189
<xsd:attribute name="fallback" type="xsd:string" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected static function getBundleDefaultConfig()
146146
'enabled' => false,
147147
'fallbacks' => array('en'),
148148
'logging' => true,
149+
'paths' => array(),
149150
),
150151
'validation' => array(
151152
'enabled' => false,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ public function testTranslatorMultipleFallbacks()
257257
$this->assertEquals(array('en', 'fr'), $calls[0][1][0]);
258258
}
259259

260+
/**
261+
* @expectedException \InvalidArgumentException
262+
* @expectedExceptionMessage The "foo" translation path does not exist.
263+
*/
264+
public function testTranslatorWithInvalidPaths()
265+
{
266+
$container = $this->createContainer();
267+
$loader = new FrameworkExtension();
268+
$loader->load(array(array('translator' => array('paths' => array('foo')))), $container);
269+
}
270+
260271
/**
261272
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
262273
*/

0 commit comments

Comments
 (0)