[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')
|
->info('translator configuration')
|
||||||
->canBeEnabled()
|
->canBeEnabled()
|
||||||
->fixXmlConfig('fallback')
|
->fixXmlConfig('fallback')
|
||||||
|
->fixXmlConfig('path')
|
||||||
->children()
|
->children()
|
||||||
->arrayNode('fallbacks')
|
->arrayNode('fallbacks')
|
||||||
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
|
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
|
||||||
@ -582,6 +583,9 @@ class Configuration implements ConfigurationInterface
|
|||||||
->defaultValue(array('en'))
|
->defaultValue(array('en'))
|
||||||
->end()
|
->end()
|
||||||
->booleanNode('logging')->defaultValue($this->debug)->end()
|
->booleanNode('logging')->defaultValue($this->debug)->end()
|
||||||
|
->arrayNode('paths')
|
||||||
|
->prototype('scalar')->end()
|
||||||
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
@ -692,6 +692,13 @@ class FrameworkExtension extends Extension
|
|||||||
$dirs[] = $dir;
|
$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')) {
|
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,7 @@
|
|||||||
<xsd:complexType name="translator">
|
<xsd:complexType name="translator">
|
||||||
<xsd:sequence>
|
<xsd:sequence>
|
||||||
<xsd:element name="fallback" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
<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:sequence>
|
||||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||||
<xsd:attribute name="fallback" type="xsd:string" />
|
<xsd:attribute name="fallback" type="xsd:string" />
|
||||||
|
@ -146,6 +146,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
'fallbacks' => array('en'),
|
'fallbacks' => array('en'),
|
||||||
'logging' => true,
|
'logging' => true,
|
||||||
|
'paths' => array(),
|
||||||
),
|
),
|
||||||
'validation' => array(
|
'validation' => array(
|
||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
|
@ -50,6 +50,7 @@ $container->loadFromExtension('framework', array(
|
|||||||
'translator' => array(
|
'translator' => array(
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'fallback' => 'fr',
|
'fallback' => 'fr',
|
||||||
|
'paths' => array('%kernel.root_dir%/Fixtures/translations'),
|
||||||
),
|
),
|
||||||
'validation' => array(
|
'validation' => array(
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
custom:
|
||||||
|
paths: test
|
@ -34,7 +34,9 @@
|
|||||||
<framework:resource>theme2</framework:resource>
|
<framework:resource>theme2</framework:resource>
|
||||||
</framework:form>
|
</framework:form>
|
||||||
</framework:templating>
|
</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:validation enabled="true" cache="apc" />
|
||||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||||
<framework:serializer enabled="true" />
|
<framework:serializer enabled="true" />
|
||||||
|
@ -39,6 +39,7 @@ framework:
|
|||||||
translator:
|
translator:
|
||||||
enabled: true
|
enabled: true
|
||||||
fallback: fr
|
fallback: fr
|
||||||
|
paths: ['%kernel.root_dir%/Fixtures/translations']
|
||||||
validation:
|
validation:
|
||||||
enabled: true
|
enabled: true
|
||||||
cache: apc
|
cache: apc
|
||||||
|
@ -244,6 +244,11 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$files,
|
$files,
|
||||||
'->registerTranslatorConfiguration() finds Security translation resources'
|
'->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();
|
$calls = $container->getDefinition('translator.default')->getMethodCalls();
|
||||||
$this->assertEquals(array('fr'), $calls[0][1][0]);
|
$this->assertEquals(array('fr'), $calls[0][1][0]);
|
||||||
|
Reference in New Issue
Block a user