Skip to content

Commit 6194a60

Browse files
committed
Rename translation:update to translation:extract
1 parent adfe868 commit 6194a60

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
* Add support for configuring log level, and status code by exception class
1919
* Bind the `default_context` parameter onto serializer's encoders and normalizers
2020
* Add support for `statusCode` default parameter when loading a template directly from route using the `Symfony\Bundle\FrameworkBundle\Controller\TemplateController` controller
21+
* Deprecate `translation:update` command, use `translation:extract` instead
2122

2223
5.3
2324
---

Command/TranslationUpdateCommand.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
19+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1920
use Symfony\Component\Console\Output\OutputInterface;
2021
use Symfony\Component\Console\Style\SymfonyStyle;
2122
use Symfony\Component\HttpKernel\KernelInterface;
@@ -41,8 +42,8 @@ class TranslationUpdateCommand extends Command
4142
private const DESC = 'desc';
4243
private const SORT_ORDERS = [self::ASC, self::DESC];
4344

44-
protected static $defaultName = 'translation:update';
45-
protected static $defaultDescription = 'Update the translation file';
45+
protected static $defaultName = 'translation:extract|translation:update';
46+
protected static $defaultDescription = 'Extract missing translations keys from code to translation files.';
4647

4748
private $writer;
4849
private $reader;
@@ -80,9 +81,9 @@ protected function configure()
8081
new InputOption('output-format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format (deprecated)'),
8182
new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'xlf12'),
8283
new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'),
83-
new InputOption('force', null, InputOption::VALUE_NONE, 'Should the update be done'),
84+
new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'),
8485
new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'),
85-
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to update'),
86+
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to extract'),
8687
new InputOption('xliff-version', null, InputOption::VALUE_OPTIONAL, 'Override the default xliff version (deprecated)'),
8788
new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically', 'asc'),
8889
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()
126127
*/
127128
protected function execute(InputInterface $input, OutputInterface $output): int
128129
{
130+
$io = new SymfonyStyle($input, $output);
131+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
132+
133+
if ('translation:update' === $input->getFirstArgument()) {
134+
$errorIo->caution('Command "translation:update" is deprecated since version 5.4 and will be removed in Symfony 6.0. Use "translation:extract" instead.');
135+
}
136+
129137
$io = new SymfonyStyle($input, $output);
130138
$errorIo = $io->getErrorStyle();
131139

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12531253
{
12541254
if (!$this->isConfigEnabled($container, $config)) {
12551255
$container->removeDefinition('console.command.translation_debug');
1256-
$container->removeDefinition('console.command.translation_update');
1256+
$container->removeDefinition('console.command.translation_extract');
12571257
$container->removeDefinition('console.command.translation_pull');
12581258
$container->removeDefinition('console.command.translation_push');
12591259

@@ -1320,8 +1320,8 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
13201320
$container->getDefinition('console.command.translation_debug')->replaceArgument(5, $transPaths);
13211321
}
13221322

1323-
if ($container->hasDefinition('console.command.translation_update')) {
1324-
$container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths);
1323+
if ($container->hasDefinition('console.command.translation_extract')) {
1324+
$container->getDefinition('console.command.translation_extract')->replaceArgument(6, $transPaths);
13251325
}
13261326

13271327
if (null === $defaultDir) {

Resources/config/console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
])
225225
->tag('console.command')
226226

227-
->set('console.command.translation_update', TranslationUpdateCommand::class)
227+
->set('console.command.translation_extract', TranslationUpdateCommand::class)
228228
->args([
229229
service('translation.writer'),
230230
service('translation.reader'),

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,58 @@ class TranslationUpdateCommandTest extends TestCase
2929
private $fs;
3030
private $translationDir;
3131

32-
public function testDumpMessagesAndClean()
32+
public function testDumpMessagesAndCleanWithDeprecatedCommandName()
3333
{
3434
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
3535
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
3636
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
3737
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
3838
}
3939

40+
public function testDumpMessagesAndClean()
41+
{
42+
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
43+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
44+
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
45+
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
46+
}
47+
4048
public function testDumpMessagesAsTreeAndClean()
4149
{
4250
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
43-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]);
51+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]);
4452
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
4553
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
4654
}
4755

4856
public function testDumpSortedMessagesAndClean()
4957
{
5058
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
51-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']);
59+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']);
5260
$this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
5361
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
5462
}
5563

5664
public function testDumpReverseSortedMessagesAndClean()
5765
{
5866
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
59-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']);
67+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']);
6068
$this->assertMatchesRegularExpression("/\*test\*foo\*bar/", preg_replace('/\s+/', '', $tester->getDisplay()));
6169
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
6270
}
6371

6472
public function testDumpSortWithoutValueAndClean()
6573
{
6674
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
67-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']);
75+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']);
6876
$this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
6977
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
7078
}
7179

7280
public function testDumpWrongSortAndClean()
7381
{
7482
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
75-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']);
83+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']);
7684
$this->assertMatchesRegularExpression('/\[ERROR\] Wrong sort order/', $tester->getDisplay());
7785
}
7886

@@ -84,15 +92,15 @@ public function testDumpMessagesAndCleanInRootDirectory()
8492
$this->fs->mkdir($this->translationDir.'/templates');
8593

8694
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
87-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
95+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
8896
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
8997
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
9098
}
9199

92100
public function testDumpTwoMessagesAndClean()
93101
{
94102
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'bar' => 'bar']]);
95-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
103+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
96104
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
97105
$this->assertMatchesRegularExpression('/bar/', $tester->getDisplay());
98106
$this->assertMatchesRegularExpression('/2 messages were successfully extracted/', $tester->getDisplay());
@@ -101,15 +109,15 @@ public function testDumpTwoMessagesAndClean()
101109
public function testDumpMessagesForSpecificDomain()
102110
{
103111
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]);
104-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']);
112+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']);
105113
$this->assertMatchesRegularExpression('/bar/', $tester->getDisplay());
106114
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
107115
}
108116

109117
public function testWriteMessages()
110118
{
111119
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
112-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]);
120+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]);
113121
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
114122
}
115123

@@ -121,14 +129,14 @@ public function testWriteMessagesInRootDirectory()
121129
$this->fs->mkdir($this->translationDir.'/templates');
122130

123131
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
124-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]);
132+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--force' => true]);
125133
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
126134
}
127135

128136
public function testWriteMessagesForSpecificDomain()
129137
{
130138
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]);
131-
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']);
139+
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']);
132140
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
133141
}
134142

@@ -211,7 +219,7 @@ function ($path, $catalogue) use ($loadedMessages) {
211219
$application = new Application($kernel);
212220
$application->add($command);
213221

214-
return new CommandTester($application->find('translation:update'));
222+
return new CommandTester($application->find('translation:extract'));
215223
}
216224

217225
private function getBundle($path)

0 commit comments

Comments
 (0)