feature #32543 [FrameworkBundle] add config translator cache_dir (Raulnet)
This PR was submitted for the 4.3 branch but it was squashed and merged into the 4.4 branch instead (closes #32543).
Discussion
----------
[FrameworkBundle] add config translator cache_dir
| Q | A
| ------------- | ---
| Branch? | 4.4 (be careful when merging)
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #32542
| License | MIT
Now the parameter cache_dir of Translator constructor can be change or disable on config
```yaml
#framework.yaml
framework:
...
translator:
cache_dir: null #(cache disable)
...
```
Commits
-------
7613c7d1de
[FrameworkBundle] add config translator cache_dir
This commit is contained in:
commit
35bf2fa9b5
@ -762,6 +762,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->end()
|
->end()
|
||||||
->booleanNode('logging')->defaultValue(false)->end()
|
->booleanNode('logging')->defaultValue(false)->end()
|
||||||
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
|
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
|
||||||
|
->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/translations')->end()
|
||||||
->scalarNode('default_path')
|
->scalarNode('default_path')
|
||||||
->info('The default path used to load translations')
|
->info('The default path used to load translations')
|
||||||
->defaultValue('%kernel.project_dir%/translations')
|
->defaultValue('%kernel.project_dir%/translations')
|
||||||
|
@ -1118,6 +1118,10 @@ class FrameworkExtension extends Extension
|
|||||||
$translator = $container->findDefinition('translator.default');
|
$translator = $container->findDefinition('translator.default');
|
||||||
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
|
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
|
||||||
|
|
||||||
|
$defaultOptions = $translator->getArgument(4);
|
||||||
|
$defaultOptions['cache_dir'] = $config['cache_dir'];
|
||||||
|
$translator->setArgument(4, $defaultOptions);
|
||||||
|
|
||||||
$container->setParameter('translator.logging', $config['logging']);
|
$container->setParameter('translator.logging', $config['logging']);
|
||||||
$container->setParameter('translator.default_path', $config['default_path']);
|
$container->setParameter('translator.default_path', $config['default_path']);
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@
|
|||||||
<xsd:attribute name="fallback" type="xsd:string" />
|
<xsd:attribute name="fallback" type="xsd:string" />
|
||||||
<xsd:attribute name="logging" type="xsd:boolean" />
|
<xsd:attribute name="logging" type="xsd:boolean" />
|
||||||
<xsd:attribute name="formatter" type="xsd:string" />
|
<xsd:attribute name="formatter" type="xsd:string" />
|
||||||
|
<xsd:attribute name="cache-dir" type="xsd:string" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="validation">
|
<xsd:complexType name="validation">
|
||||||
|
@ -241,6 +241,7 @@ class ConfigurationTest extends TestCase
|
|||||||
'translator' => [
|
'translator' => [
|
||||||
'enabled' => !class_exists(FullStack::class),
|
'enabled' => !class_exists(FullStack::class),
|
||||||
'fallbacks' => [],
|
'fallbacks' => [],
|
||||||
|
'cache_dir' => '%kernel.cache_dir%/translations',
|
||||||
'logging' => false,
|
'logging' => false,
|
||||||
'formatter' => 'translator.formatter.default',
|
'formatter' => 'translator.formatter.default',
|
||||||
'paths' => [],
|
'paths' => [],
|
||||||
|
@ -46,6 +46,7 @@ $container->loadFromExtension('framework', [
|
|||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'fallback' => 'fr',
|
'fallback' => 'fr',
|
||||||
'paths' => ['%kernel.project_dir%/Fixtures/translations'],
|
'paths' => ['%kernel.project_dir%/Fixtures/translations'],
|
||||||
|
'cache_dir' => '%kernel.cache_dir%/translations',
|
||||||
],
|
],
|
||||||
'validation' => [
|
'validation' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$container->loadFromExtension('framework', [
|
||||||
|
'translator' => [
|
||||||
|
'cache_dir' => null,
|
||||||
|
],
|
||||||
|
]);
|
@ -26,7 +26,7 @@
|
|||||||
</framework:format>
|
</framework:format>
|
||||||
</framework:request>
|
</framework:request>
|
||||||
<framework:assets version="v1" />
|
<framework:assets version="v1" />
|
||||||
<framework:translator enabled="true" fallback="fr" logging="true">
|
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="%kernel.cache_dir%/translations">
|
||||||
<framework:path>%kernel.project_dir%/Fixtures/translations</framework:path>
|
<framework:path>%kernel.project_dir%/Fixtures/translations</framework:path>
|
||||||
</framework:translator>
|
</framework:translator>
|
||||||
<framework:validation enabled="true" />
|
<framework:validation enabled="true" />
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
|
||||||
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:framework="http://symfony.com/schema/dic/symfony"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
|
||||||
|
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
|
||||||
|
|
||||||
|
<framework:config secret="s3cr3t">
|
||||||
|
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="null" />
|
||||||
|
</framework:config>
|
||||||
|
</container>
|
@ -36,6 +36,7 @@ framework:
|
|||||||
enabled: true
|
enabled: true
|
||||||
fallback: fr
|
fallback: fr
|
||||||
default_path: '%kernel.project_dir%/translations'
|
default_path: '%kernel.project_dir%/translations'
|
||||||
|
cache_dir: '%kernel.cache_dir%/translations'
|
||||||
paths: ['%kernel.project_dir%/Fixtures/translations']
|
paths: ['%kernel.project_dir%/Fixtures/translations']
|
||||||
validation:
|
validation:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
framework:
|
||||||
|
translator:
|
||||||
|
cache_dir: ~
|
@ -51,11 +51,11 @@ use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|||||||
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
||||||
use Symfony\Component\Serializer\Serializer;
|
use Symfony\Component\Serializer\Serializer;
|
||||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
|
||||||
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
|
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
|
||||||
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
|
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
|
||||||
use Symfony\Component\Workflow;
|
use Symfony\Component\Workflow;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
abstract class FrameworkExtensionTest extends TestCase
|
abstract class FrameworkExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -783,6 +783,9 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
|
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
|
||||||
$options = $container->getDefinition('translator.default')->getArgument(4);
|
$options = $container->getDefinition('translator.default')->getArgument(4);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('cache_dir', $options);
|
||||||
|
$this->assertSame($container->getParameter('kernel.cache_dir').'/translations', $options['cache_dir']);
|
||||||
|
|
||||||
$files = array_map('realpath', $options['resource_files']['en']);
|
$files = array_map('realpath', $options['resource_files']['en']);
|
||||||
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
|
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
@ -853,6 +856,13 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$this->assertEquals(['en', 'fr'], $calls[1][1][0]);
|
$this->assertEquals(['en', 'fr'], $calls[1][1][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTranslatorCacheDirDisabled()
|
||||||
|
{
|
||||||
|
$container = $this->createContainerFromFile('translator_cache_dir_disabled');
|
||||||
|
$options = $container->getDefinition('translator.default')->getArgument(4);
|
||||||
|
$this->assertNull($options['cache_dir']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user