Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8ad79a

Browse filesBrowse files
committed
fix translation lint compatibility with the PseudoLocalizationTranslator
1 parent f24ac9e commit c8ad79a
Copy full SHA for c8ad79a

File tree

3 files changed

+57
-1
lines changed
Filter options

3 files changed

+57
-1
lines changed
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
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+
$translator = $container->findDefinition('translator');
28+
$translatorClass = $container->getParameterBag()->resolveValue($translator->getClass());
29+
30+
if (!is_subclass_of($translatorClass, TranslatorInterface::class) || !is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
31+
$container->removeDefinition('console.command.translation_lint');
32+
}
33+
}
34+
}

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+3Lines 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);

‎src/Symfony/Component/Translation/PseudoLocalizationTranslator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/PseudoLocalizationTranslator.php
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14+
use Symfony\Component\Translation\Exception\LogicException;
1415
use Symfony\Contracts\Translation\TranslatorInterface;
1516

1617
/**
1718
* This translator should only be used in a development environment.
1819
*/
19-
final class PseudoLocalizationTranslator implements TranslatorInterface
20+
final class PseudoLocalizationTranslator implements TranslatorInterface, TranslatorBagInterface
2021
{
2122
private const EXPANSION_CHARACTER = '~';
2223

@@ -115,6 +116,24 @@ public function getLocale(): string
115116
return $this->translator->getLocale();
116117
}
117118

119+
public function getCatalogue(?string $locale = null): MessageCatalogueInterface
120+
{
121+
if (!$this->translator instanceof TranslatorBagInterface) {
122+
throw new LogicException(sprintf('The %s() method cannot be called as the wrapped translator class "%s" does not implement the "%s".', __METHOD__, $this->translator::class, TranslatorBagInterface::class));
123+
}
124+
125+
return $this->translator->getCatalogue($locale);
126+
}
127+
128+
public function getCatalogues(): array
129+
{
130+
if (!$this->translator instanceof TranslatorBagInterface) {
131+
throw new LogicException(sprintf('The %s() method cannot be called as the wrapped translator class "%s" does not implement the "%s".', __METHOD__, $this->translator::class, TranslatorBagInterface::class));
132+
}
133+
134+
return $this->translator->getCatalogues();
135+
}
136+
118137
private function getParts(string $originalTrans): array
119138
{
120139
if (!$this->parseHTML) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.