8000 Extracting from services that have the translator injected into them · symfony/symfony@4eea56e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4eea56e

Browse files
committed
Extracting from services that have the translator injected into them
1 parent 533d4d4 commit 4eea56e

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private function extractMessages(string $locale, array $transPaths): MessageCata
346346
{
347347
$extractedCatalogue = new MessageCatalogue($locale);
348348
foreach ($transPaths as $path) {
349-
if (is_dir($path)) {
349+
if (is_dir($path) || is_file($path)) {
350350
$this->extractor->extract($path, $extractedCatalogue);
351351
}
352352
}

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
206206
$errorIo->comment('Parsing templates...');
207207
$this->extractor->setPrefix($input->getOption('prefix'));
208208
foreach ($viewsPaths as $path) {
209-
if (is_dir($path)) {
209+
if (is_dir($path) || is_file($path)) {
210210
$this->extractor->extract($path, $extractedCatalogue);
211211
}
212212
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function build(ContainerBuilder $container)
9999
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
100100
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
101101
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
102-
$this->addCompilerPassIfExists($container, TranslatorPass::class);
102+
$this->addCompilerPassIfExists($container, TranslatorPass::class, PassConfig::TYPE_BEFORE_REMOVING, 32);
103103
$container->addCompilerPass(new LoggingTranslatorPass());
104104
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
105105
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);

src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Symfony\Component\Translation\DependencyInjection;
1313

14+
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Reference;
19+
use Symfony\Contracts\Translation\TranslatorInterface;
1820

1921
class TranslatorPass implements CompilerPassInterface
2022
{
@@ -69,6 +71,18 @@ public function process(ContainerBuilder $container)
6971
}
7072

7173
$paths = $container->getDefinition('twig.template_iterator')->getArgument(2);
74+
foreach ($container->getDefinitions() as $definition) {
75+
$arguments = array_merge($definition->getProperties(), $definition->getBindings(), $definition->getArguments(), ...array_column($definition->getMethodCalls(), 1));
76+
foreach ($arguments as $argument) {
77+
if ($argument instanceof BoundArgument) {
78+
list($argument) = $argument->getValues();
79+
}
80+
if ($argument instanceof Reference && $container->hasDefinition($argument) && is_subclass_of($container->findDefinition($argument)->getClass(), TranslatorInterface::class) && ($r = $container->getReflectionClass($definition->getClass())) && !$r->isInterface()) {
81+
$paths[$r->getFileName()] = true;
82+
}
83+
}
84+
}
85+
$paths = array_keys($paths);
7286

7387
if ($container->hasDefinition($this->debugCommandServiceId)) {
7488
$container->getDefinition($this->debugCommandServiceId)->replaceArgument(4, $container->getParameter('twig.default_path'));

0 commit comments

Comments
 (0)
0