From 6cd50d790b6774cae4e6e0a85b3672f3da1f6e2c Mon Sep 17 00:00:00 2001 From: Khoo Yong Jun Date: Mon, 25 Oct 2021 23:32:07 +0800 Subject: [PATCH] modifying locale completion for only enabled locales, and inject during config/console for the enabled locales value --- .../FrameworkBundle/Command/TranslationUpdateCommand.php | 7 ++++--- .../Bundle/FrameworkBundle/Resources/config/console.php | 1 + .../Command/TranslationUpdateCommandCompletionTest.php | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 746898b680b00..e22fafb9d880f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -22,7 +22,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\KernelInterface; -use Symfony\Component\Intl\Locales; use Symfony\Component\Translation\Catalogue\MergeOperation; use Symfony\Component\Translation\Catalogue\TargetOperation; use Symfony\Component\Translation\Extractor\ExtractorInterface; @@ -60,8 +59,9 @@ class TranslationUpdateCommand extends Command private $defaultViewsPath; private $transPaths; private $codePaths; + private $enabledLocales; - public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = []) + public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = [], array $enabledLocales = []) { parent::__construct(); @@ -73,6 +73,7 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade $this->defaultViewsPath = $defaultViewsPath; $this->transPaths = $transPaths; $this->codePaths = $codePaths; + $this->enabledLocales = $enabledLocales; } /** @@ -311,7 +312,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void { if ($input->mustSuggestArgumentValuesFor('locale')) { - $suggestions->suggestValues(Locales::getLocales()); + $suggestions->suggestValues($this->enabledLocales); return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php index 81af31d7260a2..e4db50c815360 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php @@ -236,6 +236,7 @@ null, // twig.default_path [], // Translator paths [], // Twig paths + param('kernel.enabled_locales'), ]) ->tag('console.command') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandCompletionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandCompletionTest.php index 4a5d3cba46961..ec001de771ef0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandCompletionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandCompletionTest.php @@ -20,7 +20,6 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\KernelInterface; -use Symfony\Component\Intl\Locales; use Symfony\Component\Translation\Extractor\ExtractorInterface; use Symfony\Component\Translation\Reader\TranslationReader; use Symfony\Component\Translation\Translator; @@ -45,7 +44,7 @@ public function testComplete(array $input, array $expectedSuggestions) public function provideCompletionSuggestions() { - yield 'locale' => [[''], Locales::getLocales()]; + yield 'locale' => [[''], ['en', 'fr']]; yield 'bundle' => [['en', ''], ['BaseBundle']]; yield 'domain with locale' => [['en', '--domain=m'], ['messages']]; yield 'domain without locale' => [['--domain=m'], []]; @@ -127,7 +126,7 @@ function ($path, $catalogue) use ($loadedMessages) { ->method('getContainer') ->willReturn($container); - $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths); + $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths, ['en', 'fr']); $application = new Application($kernel); $application->add($command);