From b02ae5050c20c451907f8ce40d29a4a1e22b91a1 Mon Sep 17 00:00:00 2001 From: Nate Wiebe Date: Wed, 17 Feb 2021 16:17:23 -0500 Subject: [PATCH] [FrameworkBundle][Translation] Extract translation IDs from all of src --- .../Command/TranslationDebugCommand.php | 21 ++++++++++--------- .../Command/TranslationUpdateCommand.php | 19 +++++++++-------- .../Command/TranslationDebugCommandTest.php | 4 ++-- .../Command/TranslationUpdateCommandTest.php | 4 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 8cb80babe61cb..ed1e6b2611032 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -55,9 +55,9 @@ class TranslationDebugCommand extends Command private $defaultTransPath; private $defaultViewsPath; private $transPaths; - private $viewsPaths; + private $codePaths; - public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $viewsPaths = []) + public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = []) { parent::__construct(); @@ -67,7 +67,7 @@ public function __construct(TranslatorInterface $translator, TranslationReaderIn $this->defaultTransPath = $defaultTransPath; $this->defaultViewsPath = $defaultViewsPath; $this->transPaths = $transPaths; - $this->viewsPaths = $viewsPaths; + $this->codePaths = $codePaths; } /** @@ -139,9 +139,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->defaultTransPath) { $transPaths[] = $this->defaultTransPath; } - $viewsPaths = $this->viewsPaths; + $codePaths = $this->codePaths; + $codePaths[] = $kernel->getProjectDir().'/src'; if ($this->defaultViewsPath) { - $viewsPaths[] = $this->defaultViewsPath; + $codePaths[] = $this->defaultViewsPath; } // Override with provided Bundle info @@ -150,19 +151,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $bundle = $kernel->getBundle($input->getArgument('bundle')); $bundleDir = $bundle->getPath(); $transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations']; - $viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates']; + $codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates']; if ($this->defaultTransPath) { $transPaths[] = $this->defaultTransPath; } if ($this->defaultViewsPath) { - $viewsPaths[] = $this->defaultViewsPath; + $codePaths[] = $this->defaultViewsPath; } } catch (\InvalidArgumentException $e) { // such a bundle does not exist, so treat the argument as path $path = $input->getArgument('bundle'); $transPaths = [$path.'/translations']; - $viewsPaths = [$path.'/templates']; + $codePaths = [$path.'/templates']; if (!is_dir($transPaths[0]) && !isset($transPaths[1])) { throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0])); @@ -172,12 +173,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($kernel->getBundles() as $bundle) { $bundleDir = $bundle->getPath(); $transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations'; - $viewsPaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates'; + $codePaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates'; } } // Extract used messages - $extractedCatalogue = $this->extractMessages($locale, $viewsPaths); + $extractedCatalogue = $this->extractMessages($locale, $codePaths); // Load defined messages $currentCatalogue = $this->loadCurrentMessages($locale, $transPaths); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 5f61f7f7fbebc..39dcc30a60193 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -51,9 +51,9 @@ class TranslationUpdateCommand extends Command private $defaultTransPath; private $defaultViewsPath; private $transPaths; - private $viewsPaths; + private $codePaths; - public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $viewsPaths = []) + public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = []) { parent::__construct(); @@ -64,7 +64,7 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade $this->defaultTransPath = $defaultTransPath; $this->defaultViewsPath = $defaultViewsPath; $this->transPaths = $transPaths; - $this->viewsPaths = $viewsPaths; + $this->codePaths = $codePaths; } /** @@ -150,9 +150,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->defaultTransPath) { $transPaths[] = $this->defaultTransPath; } - $viewsPaths = $this->viewsPaths; + $codePaths = $this->codePaths; + $codePaths[] = $kernel->getProjectDir().'/src'; if ($this->defaultViewsPath) { - $viewsPaths[] = $this->defaultViewsPath; + $codePaths[] = $this->defaultViewsPath; } $currentName = 'default directory'; @@ -162,12 +163,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $foundBundle = $kernel->getBundle($input->getArgument('bundle')); $bundleDir = $foundBundle->getPath(); $transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations']; - $viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates']; + $codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates']; if ($this->defaultTransPath) { $transPaths[] = $this->defaultTransPath; } if ($this->defaultViewsPath) { - $viewsPaths[] = $this->defaultViewsPath; + $codePaths[] = $this->defaultViewsPath; } $currentName = $foundBundle->getName(); } catch (\InvalidArgumentException $e) { @@ -175,7 +176,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $path = $input->getArgument('bundle'); $transPaths = [$path.'/translations']; - $viewsPaths = [$path.'/templates']; + $codePaths = [$path.'/templates']; if (!is_dir($transPaths[0]) && !isset($transPaths[1])) { throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0])); @@ -190,7 +191,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $extractedCatalogue = new MessageCatalogue($input->getArgument('locale')); $io->comment('Parsing templates...'); $this->extractor->setPrefix($input->getOption('prefix')); - foreach ($viewsPaths as $path) { + foreach ($codePaths as $path) { if (is_dir($path) || is_file($path)) { $this->extractor->extract($path, $extractedCatalogue); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index 2bdbcbf44753f..5cdf62e470066 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php @@ -139,7 +139,7 @@ protected function tearDown(): void $this->fs->remove($this->translationDir); } - private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester + private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $codePaths = []): CommandTester { $translator = $this->createMock(Translator::class); $translator @@ -190,7 +190,7 @@ function ($path, $catalogue) use ($loadedMessages) { ->method('getContainer') ->willReturn($container); - $command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths); + $command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths); $application = new Application($kernel); $application->add($command); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index 7e1c90d051f67..35ce89f63887c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -148,7 +148,7 @@ protected function tearDown(): void /** * @return CommandTester */ - private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = []) + private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $codePaths = []) { $translator = $this->createMock(Translator::class); $translator @@ -209,7 +209,7 @@ function ($path, $catalogue) use ($loadedMessages) { ->method('getContainer') ->willReturn($container); - $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths); + $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths); $application = new Application($kernel); $application->add($command); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy