Skip to content

Commit 10ad5ad

Browse files
committed
fix translation lint compatibility with the PseudoLocalizationTranslator
1 parent 4155d1d commit 10ad5ad

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\Translation\TranslatorBagInterface;
17+
use Symfony\Contracts\Translation\TranslatorInterface;
18+
19+
final class TranslationLintCommandPass implements CompilerPassInterface
20+
{
21+
public function process(ContainerBuilder $container): void
22+
{
23+
if (!$container->hasDefinition('console.command.translation_lint') || !$container->has('translator')) {
24+
return;
25+
}
26+
27+
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
28+
29+
if (!is_subclass_of($translatorClass, TranslatorInterface::class) || !is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
30+
$container->removeDefinition('console.command.translation_lint');
31+
}
32+
}
33+
}

FrameworkBundle.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
22+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationLintCommandPass;
2223
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2324
use Symfony\Bundle\FrameworkBundle\DependencyInjection\VirtualRequestStackPass;
2425
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -149,6 +150,8 @@ public function build(ContainerBuilder $container): void
149150
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class);
150151
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
151152
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
153+
// must be registered before the AddConsoleCommandPass
154+
$container->addCompilerPass(new TranslationLintCommandPass(), PassConfig::TYPE_BEFORE_REMOVING, 10);
152155
// must be registered as late as possible to get access to all Twig paths registered in
153156
// twig.template_iterator definition
154157
$this->addCompilerPassIfExists($container, TranslatorPass::class, PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);

0 commit comments

Comments
 (0)