Skip to content

Commit bc81695

Browse files
Raulnetfabpot
authored andcommitted
[FrameworkBundle] add config translator cache_dir
1 parent 75220c3 commit bc81695

File tree

11 files changed

+43
-2
lines changed

11 files changed

+43
-2
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
762762
->end()
763763
->booleanNode('logging')->defaultValue(false)->end()
764764
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
765+
->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/translations')->end()
765766
->scalarNode('default_path')
766767
->info('The default path used to load translations')
767768
->defaultValue('%kernel.project_dir%/translations')

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,10 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11181118
$translator = $container->findDefinition('translator.default');
11191119
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
11201120

1121+
$defaultOptions = $translator->getArgument(4);
1122+
$defaultOptions['cache_dir'] = $config['cache_dir'];
1123+
$translator->setArgument(4, $defaultOptions);
1124+
11211125
$container->setParameter('translator.logging', $config['logging']);
11221126
$container->setParameter('translator.default_path', $config['default_path']);
11231127

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<xsd:attribute name="fallback" type="xsd:string" />
187187
<xsd:attribute name="logging" type="xsd:boolean" />
188188
<xsd:attribute name="formatter" type="xsd:string" />
189+
<xsd:attribute name="cache-dir" type="xsd:string" />
189190
</xsd:complexType>
190191

191192
<xsd:complexType name="validation">

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ protected static function getBundleDefaultConfig()
241241
'translator' => [
242242
'enabled' => !class_exists(FullStack::class),
243243
'fallbacks' => [],
244+
'cache_dir' => '%kernel.cache_dir%/translations',
244245
'logging' => false,
245246
'formatter' => 'translator.formatter.default',
246247
'paths' => [],

Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'enabled' => true,
4747
'fallback' => 'fr',
4848
'paths' => ['%kernel.project_dir%/Fixtures/translations'],
49+
'cache_dir' => '%kernel.cache_dir%/translations',
4950
],
5051
'validation' => [
5152
'enabled' => true,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'translator' => [
5+
'cache_dir' => null,
6+
],
7+
]);

Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</framework:format>
2727
</framework:request>
2828
<framework:assets version="v1" />
29-
<framework:translator enabled="true" fallback="fr" logging="true">
29+
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="%kernel.cache_dir%/translations">
3030
<framework:path>%kernel.project_dir%/Fixtures/translations</framework:path>
3131
</framework:translator>
3232
<framework:validation enabled="true" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="null" />
11+
</framework:config>
12+
</container>

Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ framework:
3636
enabled: true
3737
fallback: fr
3838
default_path: '%kernel.project_dir%/translations'
39+
cache_dir: '%kernel.cache_dir%/translations'
3940
paths: ['%kernel.project_dir%/Fixtures/translations']
4041
validation:
4142
enabled: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
translator:
3+
cache_dir: ~

0 commit comments

Comments
 (0)