diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index a9a004735b11..a7318dd39fc5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -44,6 +44,7 @@ protected function configure() new InputOption('force', null, InputOption::VALUE_NONE, 'Should the update be done'), new InputOption('no-backup', null, InputOption::VALUE_NONE, 'Should backup be disabled'), new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'), + new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to update'), )) ->setDescription('Updates the translation file') ->setHelp(<<<'EOF' @@ -139,6 +140,11 @@ protected function execute(InputInterface $input, OutputInterface $output) } } + if (null !== $domain = $input->getOption('domain')) { + $currentCatalogue = $this->filterCatalogue($currentCatalogue, $domain); + $extractedCatalogue = $this->filterCatalogue($extractedCatalogue, $domain); + } + // process catalogues $operation = $input->getOption('clean') ? new TargetOperation($currentCatalogue, $extractedCatalogue) @@ -213,4 +219,23 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->success($resultMessage.'.'); } + + private function filterCatalogue(MessageCatalogue $catalogue, $domain) + { + $filteredCatalogue = new MessageCatalogue($catalogue->getLocale()); + + if ($messages = $catalogue->all($domain)) { + $filteredCatalogue->add($messages, $domain); + } + foreach ($catalogue->getResources() as $resource) { + $filteredCatalogue->addResource($resource); + } + if ($metadata = $catalogue->getMetadata('', $domain)) { + foreach ($metadata as $k => $v) { + $filteredCatalogue->setMetadata($k, $v, $domain); + } + } + + return $filteredCatalogue; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index f7eca9d366d3..d815c9d610a3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -25,19 +25,34 @@ class TranslationUpdateCommandTest extends \PHPUnit_Framework_TestCase public function testDumpMessagesAndClean() { - $tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'))); + $tester = $this->createCommandTester($this->getContainer(array('messages' => array('foo' => 'foo')))); $tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true)); $this->assertRegExp('/foo/', $tester->getDisplay()); $this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay()); } + public function testDumpMessagesForSpecificDomain() + { + $tester = $this->createCommandTester($this->getContainer(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar')))); + $tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain')); + $this->assertRegExp('/bar/', $tester->getDisplay()); + $this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay()); + } + public function testWriteMessages() { - $tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'))); + $tester = $this->createCommandTester($this->getContainer(array('messages' => array('foo' => 'foo')))); $tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true)); $this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay()); } + public function testWriteMessagesForSpecificDomain() + { + $tester = $this->createCommandTester($this->getContainer(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar')))); + $tester->execute(array('command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain')); + $this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay()); + } + protected function setUp() { $this->fs = new Filesystem(); @@ -82,7 +97,9 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar ->method('extract') ->will( $this->returnCallback(function ($path, $catalogue) use ($extractedMessages) { - $catalogue->add($extractedMessages); + foreach ($extractedMessages as $domain => $messages) { + $catalogue->add($messages, $domain); + } }) );