Skip to content

Commit d132942

Browse files
committed
minor #37258 [FrameworkBundle] Move translation service configuration from xml to php #37186 (malteschlueter)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [FrameworkBundle] Move translation service configuration from xml to php #37186 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #37186 | License | MIT | Doc PR | - Move translation service configuration from xml to php Commits ------- e4bc48f334 [FrameworkBundle] Move translation service configuration from xml to php #37186
2 parents 38fb9f7 + a4569d4 commit d132942

File tree

6 files changed

+196
-170
lines changed

6 files changed

+196
-170
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function load(array $configs, ContainerBuilder $container)
368368
$this->registerEsiConfiguration($config['esi'], $container, $loader);
369369
$this->registerSsiConfiguration($config['ssi'], $container, $phpLoader);
370370
$this->registerFragmentsConfiguration($config['fragments'], $container, $phpLoader);
371-
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
371+
$this->registerTranslatorConfiguration($config['translator'], $container, $phpLoader, $config['default_locale']);
372372
$this->registerProfilerConfiguration($config['profiler'], $container, $loader, $phpLoader);
373373
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
374374
$this->registerDebugConfiguration($config['php_errors'], $container, $phpLoader);
@@ -590,7 +590,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
590590
}
591591

592592
if ($this->translationConfigEnabled) {
593-
$loader->load('translation_debug.xml');
593+
$phpLoader->load('translation_debug.php');
594594

595595
$container->getDefinition('translator.data_collector')->setDecoratedService('translator');
596596
}
@@ -1086,7 +1086,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
10861086
return;
10871087
}
10881088

1089-
$loader->load('translation.xml');
1089+
$loader->load('translation.php');
10901090

10911091
// Use the "real" translator instead of the identity default
10921092
$container->setAlias('translator', 'translator.default')->setPublic(true);

Resources/config/translation.php

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer;
16+
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
17+
use Symfony\Component\Translation\Dumper\CsvFileDumper;
18+
use Symfony\Component\Translation\Dumper\IcuResFileDumper;
19+
use Symfony\Component\Translation\Dumper\IniFileDumper;
20+
use Symfony\Component\Translation\Dumper\JsonFileDumper;
21+
use Symfony\Component\Translation\Dumper\MoFileDumper;
22+
use Symfony\Component\Translation\Dumper\PhpFileDumper;
23+
use Symfony\Component\Translation\Dumper\PoFileDumper;
24+
use Symfony\Component\Translation\Dumper\QtFileDumper;
25+
use Symfony\Component\Translation\Dumper\XliffFileDumper;
26+
use Symfony\Component\Translation\Dumper\YamlFileDumper;
27+
use Symfony\Component\Translation\Extractor\ChainExtractor;
28+
use Symfony\Component\Translation\Extractor\ExtractorInterface;
29+
use Symfony\Component\Translation\Extractor\PhpExtractor;
30+
use Symfony\Component\Translation\Formatter\MessageFormatter;
31+
use Symfony\Component\Translation\Loader\CsvFileLoader;
32+
use Symfony\Component\Translation\Loader\IcuDatFileLoader;
33+
use Symfony\Component\Translation\Loader\IcuResFileLoader;
34+
use Symfony\Component\Translation\Loader\IniFileLoader;
35+
use Symfony\Component\Translation\Loader\JsonFileLoader;
36+
use Symfony\Component\Translation\Loader\MoFileLoader;
37+
use Symfony\Component\Translation\Loader\PhpFileLoader;
38+
use Symfony\Component\Translation\Loader\PoFileLoader;
39+
use Symfony\Component\Translation\Loader\QtFileLoader;
40+
use Symfony\Component\Translation\Loader\XliffFileLoader;
41+
use Symfony\Component\Translation\Loader\YamlFileLoader;
42+
use Symfony\Component\Translation\LoggingTranslator;
43+
use Symfony\Component\Translation\Reader\TranslationReader;
44+
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
45+
use Symfony\Component\Translation\Writer\TranslationWriter;
46+
use Symfony\Component\Translation\Writer\TranslationWriterInterface;
47+
use Symfony\Contracts\Translation\TranslatorInterface;
48+
49+
return static function (ContainerConfigurator $container) {
50+
$container->services()
51+
->set('translator.default', Translator::class)
52+
->args([
53+
abstract_arg('translation loaders locator'),
54+
service('translator.formatter'),
55+
param('kernel.default_locale'),
56+
abstract_arg('translation loaders ids'),
57+
[
58+
'cache_dir' => param('kernel.cache_dir').'/translations',
59+
'debug' => param('kernel.debug'),
60+
],
61+
abstract_arg('enabled locales'),
62+
])
63+
->call('setConfigCacheFactory', [service('config_cache_factory')])
64+
->tag('kernel.locale_aware')
65+
66+
->alias(TranslatorInterface::class, 'translator')
67+
68+
->set('translator.logging', LoggingTranslator::class)
69+
->args([
70+
service('translator.logging.inner'),
71+
service('logger'),
72+
])
73+
->tag('monolog.logger', ['channel' => 'translation'])
74+
75+
->set('translator.formatter.default', MessageFormatter::class)
76+
->args([service('identity_translator')])
77+
78+
->set('translation.loader.php', PhpFileLoader::class)
79+
->tag('translation.loader', ['alias' => 'php'])
80+
81+
->set('translation.loader.yml', YamlFileLoader::class)
82+
->tag('translation.loader', ['alias' => 'yaml', 'legacy-alias' => 'yml'])
83+
84+
->set('translation.loader.xliff', XliffFileLoader::class)
85+
->tag('translation.loader', ['alias' => 'xlf', 'legacy-alias' => 'xliff'])
86+
87+
->set('translation.loader.po', PoFileLoader::class)
88+
->tag('translation.loader', ['alias' => 'po'])
89+
90+
->set('translation.loader.mo', MoFileLoader::class)
91+
->tag('translation.loader', ['alias' => 'mo'])
92+
93+
->set('translation.loader.qt', QtFileLoader::class)
94+
->tag('translation.loader', ['alias' => 'ts'])
95+
96+
->set('translation.loader.csv', CsvFileLoader::class)
97+
->tag('translation.loader', ['alias' => 'csv'])
98+
99+
->set('translation.loader.res', IcuResFileLoader::class)
100+
->tag('translation.loader', ['alias' => 'res'])
101+
102+
->set('translation.loader.dat', IcuDatFileLoader::class)
103+
->tag('translation.loader', ['alias' => 'dat'])
104+
105+
->set('translation.loader.ini', IniFileLoader::class)
106+
->tag('translation.loader', ['alias' => 'ini'])
107+
108+
->set('translation.loader.json', JsonFileLoader::class)
109+
->tag('translation.loader', ['alias' => 'json'])
110+
111+
->set('translation.dumper.php', PhpFileDumper::class)
112+
->tag('translation.dumper', ['alias' => 'php'])
113+
114+
->set('translation.dumper.xliff', XliffFileDumper::class)
115+
->tag('translation.dumper', ['alias' => 'xlf'])
116+
117+
->set('translation.dumper.po', PoFileDumper::class)
118+
->tag('translation.dumper', ['alias' => 'po'])
119+
120+
->set('translation.dumper.mo', MoFileDumper::class)
121+
->tag('translation.dumper', ['alias' => 'mo'])
122+
123+
->set('translation.dumper.yml', YamlFileDumper::class)
124+
->tag('translation.dumper', ['alias' => 'yml'])
125+
126+
->set('translation.dumper.yaml', YamlFileDumper::class)
127+
->args(['yaml'])
128+
->tag('translation.dumper', ['alias' => 'yaml'])
129+
130+
->set('translation.dumper.qt', QtFileDumper::class)
131+
->tag('translation.dumper', ['alias' => 'ts'])
132+
133+
->set('translation.dumper.csv', CsvFileDumper::class)
134+
->tag('translation.dumper', ['alias' => 'csv'])
135+
136+
->set('translation.dumper.ini', IniFileDumper::class)
137+
->tag('translation.dumper', ['alias' => 'ini'])
138+
139+
->set('translation.dumper.json', JsonFileDumper::class)
140+
->tag('translation.dumper', ['alias' => 'json'])
141+
142+
->set('translation.dumper.res', IcuResFileDumper::class)
143+
->tag('translation.dumper', ['alias' => 'res'])
144+
145+
->set('translation.extractor.php', PhpExtractor::class)
146+
->tag('translation.extractor', ['alias' => 'php'])
147+
148+
->set('translation.reader', TranslationReader::class)
149+
->alias(TranslationReaderInterface::class, 'translation.reader')
150+
151+
->set('translation.extractor', ChainExtractor::class)
152+
->alias(ExtractorInterface::class, 'translation.extractor')
153+
154+
->set('translation.writer', TranslationWriter::class)
155+
->alias(TranslationWriterInterface::class, 'translation.writer')
156+
157+
->set('translation.warmer', TranslationsCacheWarmer::class)
158+
->args([service(ContainerInterface::class)])
159+
->tag('container.service_subscriber', ['id' => 'translator'])
160+
->tag('kernel.cache_warmer')
161+
;
162+
};

Resources/config/translation.xml

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Translation\DataCollector\TranslationDataCollector;
15+
use Symfony\Component\Translation\DataCollectorTranslator;
16+
17+
return static function (ContainerConfigurator $container) {
18+
$container->services()
19+
->set('translator.data_collector', DataCollectorTranslator::class)
20+
->args([service('translator.data_collector.inner')])
21+
22+
->set('data_collector.translation', TranslationDataCollector::class)
23+
->args([service('translator.data_collector')])
24+
->tag('data_collector', [
25+
'template' => '@WebProfiler/Collector/translation.html.twig',
26+
'id' => 'translation',
27+
'priority' => 275,
28+
])
29+
;
30+
};

Resources/config/translation_debug.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public function testMessengerInvalidTransportRouting()
729729
public function testTranslator()
730730
{
731731
$container = $this->createContainerFromFile('full');
732-
$this->assertTrue($container->hasDefinition('translator.default'), '->registerTranslatorConfiguration() loads translation.xml');
732+
$this->assertTrue($container->hasDefinition('translator.default'), '->registerTranslatorConfiguration() loads translation.php');
733733
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
734734
$options = $container->getDefinition('translator.default')->getArgument(4);
735735

0 commit comments

Comments
 (0)