1414use Symfony \Component \DependencyInjection \ContainerBuilder ;
1515use Symfony \Component \Config \FileLocator ;
1616use Symfony \Component \DependencyInjection \DefinitionDecorator ;
17+ use Symfony \Component \DependencyInjection \Reference ;
1718use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
1819use Symfony \Component \DependencyInjection \Loader ;
1920
@@ -43,6 +44,11 @@ public function load(array $configs, ContainerBuilder $container)
4344 $ this ->enableWebUi ($ container , $ config );
4445 }
4546
47+ if ($ config ['fallback_translation ' ]['enabled ' ]) {
48+ $ loader ->load ('auto_translation.yml ' );
49+ $ this ->enableFallbackAutoTranslator ($ container , $ config );
50+ }
51+
4652 foreach ($ config ['configs ' ] as $ name => &$ c ) {
4753 if (empty ($ c ['project_root ' ])) {
4854 $ c ['project_root ' ] = dirname ($ container ->getParameter ('kernel.root_dir ' ));
@@ -61,9 +67,15 @@ private function enableWebUi(ContainerBuilder $container, $config)
6167 {
6268 }
6369
64- private function configureExtractors (ContainerBuilder $ container , $ config )
70+ private function enableFallbackAutoTranslator (ContainerBuilder $ container , $ config )
6571 {
66- $ def = $ container ->getDefinition ('php_translation.extractor ' );
72+ $ externalTranslatorId = 'php_translation.translator_service. ' .$ config ['fallback_translation ' ]['service ' ];
73+ $ externalTranslatorDef = $ container ->getDefinition ($ externalTranslatorId );
74+ $ externalTranslatorDef ->addTag ('php_translation.external_translator ' );
75+ $ externalTranslatorDef ->addArgument (new Reference ($ config ['http_client ' ]));
76+ $ externalTranslatorDef ->addArgument (new Reference ($ config ['message_factory ' ]));
77+
78+ $ container ->setParameter ('php_translation.translator_service.api_key ' , $ config ['fallback_translation ' ]['api_key ' ]);
6779 }
6880
6981 public function getAlias ()
0 commit comments