8000 bug #19878 Fix translation:update command count (tgalopin) · symfony/symfony@dc733f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc733f1

Browse files
committed
bug #19878 Fix translation:update command count (tgalopin)
This PR was merged into the 2.8 branch. Discussion ---------- Fix translation:update command count | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This issue fixes a bad count in the `translation:update` command. Previously, the number was badly calculated and doubled if the translation file didn't exists. Before: ``` Messages extracted for domain "messages" (2 messages) ----------------------------------------------------- * hello.world [OK] 2 messages were successfully extracted. ``` After: ``` Messages extracted for domain "messages" (1 message) ----------------------------------------------------- * hello.world [OK] 1 message was successfully extracted. ``` Commits ------- ffdd15e Fix translation:update command count
2 parents 69afe99 + ffdd15e commit dc733f1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
160160
foreach ($operation->getDomains() as $domain) {
161161
$newKeys = array_keys($operation->getNewMessages($domain));
162162
$allKeys = array_keys($operation->getMessages($domain));
163-
$domainMessagesCount = count($newKeys) + count($allKeys);
164163

165-
$io->section(sprintf('Messages extracted for domain "<info>%s</info>" (%d messages)', $domain, $domainMessagesCount));
166-
167-
$io->listing(array_merge(
164+
$list = array_merge(
168165
array_diff($allKeys, $newKeys),
169166
array_map(function ($id) {
170167
return sprintf('<fg=green>%s</>', $id);
171168
}, $newKeys),
172169
array_map(function ($id) {
173170
return sprintf('<fg=red>%s</>', $id);
174171
}, array_keys($operation->getObsoleteMessages($domain)))
175-
));
172+
);
173+
174+
$domainMessagesCount = count($list);
175+
176+
$io->section(sprintf('Messages extracted for domain "<info>%s</info>" (%d message%s)', $domain, $domainMessagesCount, $domainMessagesCount > 1 ? 's' : ''));
177+
$io->listing($list);
176178

177179
$extractedMessagesCount += $domainMessagesCount;
178180
}
@@ -181,7 +183,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
181183
$io->comment('Xliff output version is <info>1.2</info>');
182184
}
183185

184-
$resultMessage = sprintf('%d messages were successfully extracted', $extractedMessagesCount);
186+
$resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was');
185187
}
186188

187189
if ($input->getOption('no-backup') === true) {

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public function testDumpMessagesAndClean()
2828
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo')));
2929
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true));
3030
$this->assertRegExp('/foo/', $tester->getDisplay());
31+
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
32+
}
33+
34+
public function testDumpTwoMessagesAndClean()
35+
{
36+
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo', 'bar' => 'bar')));
37+
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true));
38+
$this->assertRegExp('/foo/', $tester->getDisplay());
39+
$this->assertRegExp('/bar/', $tester->getDisplay());
3140
$this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay());
3241
}
3342

0 commit comments

Comments
 (0)
0