TranslationDumperPass.php
1 month ago
TranslationExtractorPass.php
1 month ago
TranslatorPass.php
1 month ago
TranslatorPathsPass.php
1 month ago
TranslatorPass.php
63 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation\DependencyInjection; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 14 | use IAWPSCOPED\Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
| 15 | use IAWPSCOPED\Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | use IAWPSCOPED\Symfony\Component\DependencyInjection\Reference; |
| 17 | /** @internal */ |
| 18 | class TranslatorPass implements CompilerPassInterface |
| 19 | { |
| 20 | public function process(ContainerBuilder $container) |
| 21 | { |
| 22 | if (!$container->hasDefinition('translator.default')) { |
| 23 | return; |
| 24 | } |
| 25 | $loaders = []; |
| 26 | $loaderRefs = []; |
| 27 | foreach ($container->findTaggedServiceIds('translation.loader', \true) as $id => $attributes) { |
| 28 | $loaderRefs[$id] = new Reference($id); |
| 29 | $loaders[$id][] = $attributes[0]['alias']; |
| 30 | if (isset($attributes[0]['legacy-alias'])) { |
| 31 | $loaders[$id][] = $attributes[0]['legacy-alias']; |
| 32 | } |
| 33 | } |
| 34 | if ($container->hasDefinition('translation.reader')) { |
| 35 | $definition = $container->getDefinition('translation.reader'); |
| 36 | foreach ($loaders as $id => $formats) { |
| 37 | foreach ($formats as $format) { |
| 38 | $definition->addMethodCall('addLoader', [$format, $loaderRefs[$id]]); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | $container->findDefinition('translator.default')->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))->replaceArgument(3, $loaders); |
| 43 | if (!$container->hasParameter('twig.default_path')) { |
| 44 | return; |
| 45 | } |
| 46 | $paths = \array_keys($container->getDefinition('twig.template_iterator')->getArgument(1)); |
| 47 | if ($container->hasDefinition('console.command.translation_debug')) { |
| 48 | $definition = $container->getDefinition('console.command.translation_debug'); |
| 49 | $definition->replaceArgument(4, $container->getParameter('twig.default_path')); |
| 50 | if (\count($definition->getArguments()) > 6) { |
| 51 | $definition->replaceArgument(6, $paths); |
| 52 | } |
| 53 | } |
| 54 | if ($container->hasDefinition('console.command.translation_extract')) { |
| 55 | $definition = $container->getDefinition('console.command.translation_extract'); |
| 56 | $definition->replaceArgument(5, $container->getParameter('twig.default_path')); |
| 57 | if (\count($definition->getArguments()) > 7) { |
| 58 | $definition->replaceArgument(7, $paths); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 |