Skip to content

Navigation Menu

Sign in
Appearance settings

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

[FrameworkBundle] Rename translation:update to translation:extract #43758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,58 @@ 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]);
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
$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());
}

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());
}

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());
}

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());
}

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());
}

Expand All @@ -84,15 +92,15 @@ 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());
}

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());
Expand All @@ -101,15 +109,15 @@ 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());
}

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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'),
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.