Fix translation:update command count

This commit is contained in:
Titouan Galopin 2016-09-07 10:32:40 +02:00
parent 69afe99f45
commit ffdd15ee06
2 changed files with 17 additions and 6 deletions

View File

@ -160,11 +160,8 @@ EOF
foreach ($operation->getDomains() as $domain) { foreach ($operation->getDomains() as $domain) {
$newKeys = array_keys($operation->getNewMessages($domain)); $newKeys = array_keys($operation->getNewMessages($domain));
$allKeys = array_keys($operation->getMessages($domain)); $allKeys = array_keys($operation->getMessages($domain));
$domainMessagesCount = count($newKeys) + count($allKeys);
$io->section(sprintf('Messages extracted for domain "<info>%s</info>" (%d messages)', $domain, $domainMessagesCount)); $list = array_merge(
$io->listing(array_merge(
array_diff($allKeys, $newKeys), array_diff($allKeys, $newKeys),
array_map(function ($id) { array_map(function ($id) {
return sprintf('<fg=green>%s</>', $id); return sprintf('<fg=green>%s</>', $id);
@ -172,7 +169,12 @@ EOF
array_map(function ($id) { array_map(function ($id) {
return sprintf('<fg=red>%s</>', $id); return sprintf('<fg=red>%s</>', $id);
}, array_keys($operation->getObsoleteMessages($domain))) }, array_keys($operation->getObsoleteMessages($domain)))
)); );
$domainMessagesCount = count($list);
$io->section(sprintf('Messages extracted for domain "<info>%s</info>" (%d message%s)', $domain, $domainMessagesCount, $domainMessagesCount > 1 ? 's' : ''));
$io->listing($list);
$extractedMessagesCount += $domainMessagesCount; $extractedMessagesCount += $domainMessagesCount;
} }
@ -181,7 +183,7 @@ EOF
$io->comment('Xliff output version is <info>1.2</info>'); $io->comment('Xliff output version is <info>1.2</info>');
} }
$resultMessage = sprintf('%d messages were successfully extracted', $extractedMessagesCount); $resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was');
} }
if ($input->getOption('no-backup') === true) { if ($input->getOption('no-backup') === true) {

View File

@ -28,6 +28,15 @@ class TranslationUpdateCommandTest extends \PHPUnit_Framework_TestCase
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'))); $tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo')));
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true)); $tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true));
$this->assertRegExp('/foo/', $tester->getDisplay()); $this->assertRegExp('/foo/', $tester->getDisplay());
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
}
public function testDumpTwoMessagesAndClean()
{
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo', 'bar' => 'bar')));
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true));
$this->assertRegExp('/foo/', $tester->getDisplay());
$this->assertRegExp('/bar/', $tester->getDisplay());
$this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay()); $this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay());
} }