diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 6d0816fb633b..2ee32e3c8a9c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -18,6 +18,7 @@ CHANGELOG * Add support for configuring log level, and status code by exception class * Bind the `default_context` parameter onto serializer's encoders and normalizers * Add support for `statusCode` default parameter when loading a template directly from route using the `Symfony\Bundle\FrameworkBundle\Controller\TemplateController` controller + * Deprecate `translation:update` command, use `translation:extract` instead 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index ee250f18f5dd..d639b59f268b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\HttpKernel\KernelInterface; @@ -41,8 +42,8 @@ class TranslationUpdateCommand extends Command private const DESC = 'desc'; private const SORT_ORDERS = [self::ASC, self::DESC]; - protected static $defaultName = 'translation:update'; - protected static $defaultDescription = 'Update the translation file'; + protected static $defaultName = 'translation:extract|translation:update'; + protected static $defaultDescription = 'Extract missing translations keys from code to translation files.'; private $writer; private $reader; @@ -80,9 +81,9 @@ protected function configure() new InputOption('output-format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format (deprecated)'), new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'xlf12'), new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'), - new InputOption('force', null, InputOption::VALUE_NONE, 'Should the update be done'), + new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'), new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'), - new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to update'), + new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to extract'), new InputOption('xliff-version', null, InputOption::VALUE_OPTIONAL, 'Override the default xliff version (deprecated)'), new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically', 'asc'), new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'), @@ -126,6 +127,13 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output): int { + $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; + + if ('translation:update' === $input->getFirstArgument()) { + $errorIo->caution('Command "translation:update" is deprecated since version 5.4 and will be removed in Symfony 6.0. Use "translation:extract" instead.'); + } + $io = new SymfonyStyle($input, $output); $errorIo = $io->getErrorStyle(); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index a90e8fb9a26e..06be71897147 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1253,7 +1253,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder { if (!$this->isConfigEnabled($container, $config)) { $container->removeDefinition('console.command.translation_debug'); - $container->removeDefinition('console.command.translation_update'); + $container->removeDefinition('console.command.translation_extract'); $container->removeDefinition('console.command.translation_pull'); $container->removeDefinition('console.command.translation_push'); @@ -1320,8 +1320,8 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder $container->getDefinition('console.command.translation_debug')->replaceArgument(5, $transPaths); } - if ($container->hasDefinition('console.command.translation_update')) { - $container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths); + if ($container->hasDefinition('console.command.translation_extract')) { + $container->getDefinition('console.command.translation_extract')->replaceArgument(6, $transPaths); } if (null === $defaultDir) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php index 430a710c4898..a47f713f417d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php @@ -224,7 +224,7 @@ ]) ->tag('console.command') - ->set('console.command.translation_update', TranslationUpdateCommand::class) + ->set('console.command.translation_extract', TranslationUpdateCommand::class) ->args([ service('translation.writer'), service('translation.reader'), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index 5a3d70717bcc..5c6fa8ec35ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -29,7 +29,7 @@ class TranslationUpdateCommandTest extends TestCase private $fs; private $translationDir; - public function testDumpMessagesAndClean() + public function testDumpMessagesAndCleanWithDeprecatedCommandName() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); @@ -37,10 +37,18 @@ public function testDumpMessagesAndClean() $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); } + public function testDumpMessagesAndClean() + { + $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); + $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); + $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); + } + public function testDumpMessagesAsTreeAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]); $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); } @@ -48,7 +56,7 @@ public function testDumpMessagesAsTreeAndClean() public function testDumpSortedMessagesAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']); $this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay())); $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); } @@ -56,7 +64,7 @@ public function testDumpSortedMessagesAndClean() public function testDumpReverseSortedMessagesAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']); $this->assertMatchesRegularExpression("/\*test\*foo\*bar/", preg_replace('/\s+/', '', $tester->getDisplay())); $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); } @@ -64,7 +72,7 @@ public function testDumpReverseSortedMessagesAndClean() public function testDumpSortWithoutValueAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']); $this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay())); $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); } @@ -72,7 +80,7 @@ public function testDumpSortWithoutValueAndClean() public function testDumpWrongSortAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']); $this->assertMatchesRegularExpression('/\[ERROR\] Wrong sort order/', $tester->getDisplay()); } @@ -84,7 +92,7 @@ public function testDumpMessagesAndCleanInRootDirectory() $this->fs->mkdir($this->translationDir.'/templates'); $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]); $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); } @@ -92,7 +100,7 @@ public function testDumpMessagesAndCleanInRootDirectory() public function testDumpTwoMessagesAndClean() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); $this->assertMatchesRegularExpression('/bar/', $tester->getDisplay()); $this->assertMatchesRegularExpression('/2 messages were successfully extracted/', $tester->getDisplay()); @@ -101,7 +109,7 @@ public function testDumpTwoMessagesAndClean() public function testDumpMessagesForSpecificDomain() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']); $this->assertMatchesRegularExpression('/bar/', $tester->getDisplay()); $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); } @@ -109,7 +117,7 @@ public function testDumpMessagesForSpecificDomain() public function testWriteMessages() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]); $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); } @@ -121,14 +129,14 @@ public function testWriteMessagesInRootDirectory() $this->fs->mkdir($this->translationDir.'/templates'); $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--force' => true]); $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); } public function testWriteMessagesForSpecificDomain() { $tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]); - $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']); + $tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']); $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); } @@ -211,7 +219,7 @@ function ($path, $catalogue) use ($loadedMessages) { $application = new Application($kernel); $application->add($command); - return new CommandTester($application->find('translation:update')); + return new CommandTester($application->find('translation:extract')); } private function getBundle($path) diff --git a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php index c6a1306eb3d7..e6a4b362ffcc 100644 --- a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php +++ b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php @@ -24,7 +24,7 @@ class TranslatorPass implements CompilerPassInterface private $debugCommandServiceId; private $updateCommandServiceId; - public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_update') + public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_extract') { if (0 < \func_num_args()) { trigger_deprecation('symfony/translation', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); diff --git a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php index 957e1c96d7a7..18a71c45ae66 100644 --- a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php +++ b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php @@ -43,7 +43,7 @@ class TranslatorPathsPass extends AbstractRecursivePass */ private $controllers = []; - public function __construct(string $translatorServiceId = 'translator', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_update', string $resolverServiceId = 'argument_resolver.service') + public function __construct(string $translatorServiceId = 'translator', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_extract', string $resolverServiceId = 'argument_resolver.service') { if (0 < \func_num_args()) { trigger_deprecation('symfony/translation', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); diff --git a/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPathsPassTest.php b/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPathsPassTest.php index ec803eb5a167..ec46aaa92c57 100644 --- a/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPathsPassTest.php +++ b/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPathsPassTest.php @@ -33,7 +33,7 @@ public function testProcess() $debugCommand = $container->register('console.command.translation_debug') ->setArguments([null, null, null, null, null, [], []]) ; - $updateCommand = $container->register('console.command.translation_update') + $updateCommand = $container->register('console.command.translation_extract') ->setArguments([null, null, null, null, null, null, [], []]) ; $container->register(ControllerArguments::class, ControllerArguments::class) diff --git a/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslatorPassTest.php b/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslatorPassTest.php index c8247626b650..05e57e87521e 100644 --- a/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslatorPassTest.php +++ b/src/Symfony/Component/Translation/Tests/DependencyInjection/TranslatorPassTest.php @@ -64,7 +64,7 @@ public function testValidCommandsViewPathsArgument() $debugCommand = $container->register('console.command.translation_debug') ->setArguments([null, null, null, null, null, [], []]) ; - $updateCommand = $container->register('console.command.translation_update') + $updateCommand = $container->register('console.command.translation_extract') ->setArguments([null, null, null, null, null, null, [], []]) ; $container->register('twig.template_iterator') @@ -98,7 +98,7 @@ public function testCommandsViewPathsArgumentsAreIgnoredWithOldServiceDefinition null, ]) ; - $updateCommand = $container->register('console.command.translation_update') + $updateCommand = $container->register('console.command.translation_extract') ->setArguments([ new Reference('translation.writer'), new Reference('translation.reader'),