Skip to content

Commit 88b7e7c

Browse files
committed
feature #14561 [FrameworkBundle][DX] Add option to specify additional translation loading paths (Seldaek)
This PR was squashed before being merged into the 2.8 branch (closes #14561). Discussion ---------- [FrameworkBundle][DX] Add option to specify additional translation loading paths | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #971 | License | MIT | Doc PR | TODO Thanks to this PR, next time I want to just do: ``` translator: fallback: "%locale%" paths: ['%kernel.root_dir%/../vendor/internal/package/translations'] ``` I will be able to, and won't have to dig in docs, start building a translation loader before I realize it's not what I want, dig in the framework ext, and then have to write a compiler pass to inject my file to the translator resource paths. Commits ------- bba0a25 [FrameworkBundle][DX] Add option to specify additional translation loading paths
2 parents 128140e + bba0a25 commit 88b7e7c

File tree

9 files changed

+25
-1
lines changed

9 files changed

+25
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +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()
584585
->booleanNode('logging')->defaultValue($this->debug)->end()
586+
->arrayNode('paths')
587+
->prototype('scalar')->end()
588+
->end()
585589
->end()
586590
->end()
587591
->end()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
692692
$dirs[] = $dir;
693693
}
694694
}
695+
foreach ($config['paths'] as $dir) {
696+
if (is_dir($dir)) {
697+
$dirs[] = $dir;
698+
} else {
699+
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
700+
}
701+
}
695702
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
696703
$dirs[] = $dir;
697704
}

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/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'translator' => array(
5151
'enabled' => true,
5252
'fallback' => 'fr',
53+
'paths' => array('%kernel.root_dir%/Fixtures/translations'),
5354
),
5455
'validation' => array(
5556
'enabled' => true,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
custom:
2+
paths: test

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
<framework:resource>theme2</framework:resource>
3535
</framework:form>
3636
</framework:templating>
37-
<framework:translator enabled="true" fallback="fr" logging="true" />
37+
<framework:translator enabled="true" fallback="fr" logging="true">
38+
<framework:path>%kernel.root_dir%/Fixtures/translations</framework:path>
39+
</framework:translator>
3840
<framework:validation enabled="true" cache="apc" />
3941
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
4042
<framework:serializer enabled="true" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ framework:
3939
translator:
4040
enabled: true
4141
fallback: fr
42+
paths: ['%kernel.root_dir%/Fixtures/translations']
4243
validation:
4344
enabled: true
4445
cache: apc

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ public function testTranslator()
244244
$files,
245245
'->registerTranslatorConfiguration() finds Security translation resources'
246246
);
247+
$this->assertContains(
248+
strtr(__DIR__.'/Fixtures/translations/test_paths.en.yml', '/', DIRECTORY_SEPARATOR),
249+
$files,
250+
'->registerTranslatorConfiguration() finds translation resources in custom paths'
251+
);
247252

248253
$calls = $container->getDefinition('translator.default')->getMethodCalls();
249254
$this->assertEquals(array('fr'), $calls[0][1][0]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy