Skip to content

Commit

Permalink
modifying locale completion for only enabled locales, and inject duri…
Browse files Browse the repository at this point in the history
…ng config/console for the enabled locales value
  • Loading branch information
stephenkhoo committed Oct 26, 2021
1 parent 7cfc2b8 commit 6cd50d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -73,6 +73,7 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade
$this->defaultViewsPath = $defaultViewsPath;
$this->transPaths = $transPaths;
$this->codePaths = $codePaths;
$this->enabledLocales = $enabledLocales;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -236,6 +236,7 @@
null, // twig.default_path
[], // Translator paths
[], // Twig paths
param('kernel.enabled_locales'),
])
->tag('console.command')

Expand Down
Expand Up @@ -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;
Expand All @@ -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'], []];
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6cd50d7

Please sign in to comment.