[FrameworkBundle][DX] Add option to specify additional translation loading paths
This commit is contained in:
parent
197396089f
commit
bba0a25798
@ -575,6 +575,7 @@ class Configuration implements ConfigurationInterface
|
||||
->info('translator configuration')
|
||||
->canBeEnabled()
|
||||
->fixXmlConfig('fallback')
|
||||
->fixXmlConfig('path')
|
||||
->children()
|
||||
->arrayNode('fallbacks')
|
||||
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
|
||||
@ -582,6 +583,9 @@ class Configuration implements ConfigurationInterface
|
||||
->defaultValue(array('en'))
|
||||
->end()
|
||||
->booleanNode('logging')->defaultValue($this->debug)->end()
|
||||
->arrayNode('paths')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -692,6 +692,13 @@ class FrameworkExtension extends Extension
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
}
|
||||
foreach ($config['paths'] as $dir) {
|
||||
if (is_dir($dir)) {
|
||||
$dirs[] = $dir;
|
||||
} else {
|
||||
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
|
||||
}
|
||||
}
|
||||
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
|
@ -183,6 +183,7 @@
|
||||
<xsd:complexType name="translator">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="fallback" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="path" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||
<xsd:attribute name="fallback" type="xsd:string" />
|
||||
|
@ -146,6 +146,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'enabled' => false,
|
||||
'fallbacks' => array('en'),
|
||||
'logging' => true,
|
||||
'paths' => array(),
|
||||
),
|
||||
'validation' => array(
|
||||
'enabled' => false,
|
||||
|
@ -50,6 +50,7 @@ $container->loadFromExtension('framework', array(
|
||||
'translator' => array(
|
||||
'enabled' => true,
|
||||
'fallback' => 'fr',
|
||||
'paths' => array('%kernel.root_dir%/Fixtures/translations'),
|
||||
),
|
||||
'validation' => array(
|
||||
'enabled' => true,
|
||||
|
@ -0,0 +1,2 @@
|
||||
custom:
|
||||
paths: test
|
@ -34,7 +34,9 @@
|
||||
<framework:resource>theme2</framework:resource>
|
||||
</framework:form>
|
||||
</framework:templating>
|
||||
<framework:translator enabled="true" fallback="fr" logging="true" />
|
||||
<framework:translator enabled="true" fallback="fr" logging="true">
|
||||
<framework:path>%kernel.root_dir%/Fixtures/translations</framework:path>
|
||||
</framework:translator>
|
||||
<framework:validation enabled="true" cache="apc" />
|
||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||
<framework:serializer enabled="true" />
|
||||
|
@ -39,6 +39,7 @@ framework:
|
||||
translator:
|
||||
enabled: true
|
||||
fallback: fr
|
||||
paths: ['%kernel.root_dir%/Fixtures/translations']
|
||||
validation:
|
||||
enabled: true
|
||||
cache: apc
|
||||
|
@ -244,6 +244,11 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$files,
|
||||
'->registerTranslatorConfiguration() finds Security translation resources'
|
||||
);
|
||||
$this->assertContains(
|
||||
strtr(__DIR__.'/Fixtures/translations/test_paths.en.yml', '/', DIRECTORY_SEPARATOR),
|
||||
$files,
|
||||
'->registerTranslatorConfiguration() finds translation resources in custom paths'
|
||||
);
|
||||
|
||||
$calls = $container->getDefinition('translator.default')->getMethodCalls();
|
||||
$this->assertEquals(array('fr'), $calls[0][1][0]);
|
||||
|
Reference in New Issue
Block a user