Skip to content

[FrameworkBundle][DX] Add option to specify additional translation loading paths #14561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,17 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
->info('translator configuration')
->canBeEnabled()
->fixXmlConfig('fallback')
->fixXmlConfig('path')
->children()
->arrayNode('fallbacks')
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
->prototype('scalar')->end()
->defaultValue(array('en'))
->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->arrayNode('paths')
->prototype('scalar')->end()
->end()
->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about merging this node and the fallbacks node into one single children() block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's my bad I'll fix.

->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ protected static function getBundleDefaultConfig()
'enabled' => false,
'fallbacks' => array('en'),
'logging' => true,
'paths' => array(),
),
'validation' => array(
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'translator' => array(
'enabled' => true,
'fallback' => 'fr',
'paths' => array('%kernel.root_dir%/Fixtures/translations'),
),
'validation' => array(
'enabled' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
custom:
paths: test
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ framework:
translator:
enabled: true
fallback: fr
paths: ['%kernel.root_dir%/Fixtures/translations']
validation:
enabled: true
cache: apc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ public function testTranslator()
$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]);
Expand Down