From 1951412b96c47b0b2c671834123245479ef7080d Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Sun, 29 Jun 2014 09:53:14 +0000 Subject: [PATCH] [Translation:update][Xliff Dumper] added target-language. --- .../Command/TranslationUpdateCommand.php | 2 +- .../Translation/Dumper/XliffFileDumper.php | 21 ++++++++++++++++++- .../Tests/Dumper/XliffFileDumperTest.php | 2 +- .../Tests/fixtures/resources-clean.xlf | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 2ef9d04465..93c74ef6e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -141,7 +141,7 @@ EOF // save the files if ($input->getOption('force') === true) { $output->writeln('Writing files'); - $writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath)); + $writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale'))); } } } diff --git a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php index 96c0c8a387..d881f6e6b2 100644 --- a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php @@ -20,6 +20,24 @@ use Symfony\Component\Translation\MessageCatalogue; */ class XliffFileDumper extends FileDumper { + /** + * @var string + */ + private $defaultLocale; + + /** + * {@inheritdoc} + */ + public function dump(MessageCatalogue $messages, $options = array()) + { + $this->defaultLocale = \Locale::getDefault(); + if (array_key_exists('default_locale', $options)) { + $this->defaultLocale = $options['default_locale']; + } + + parent::dump($messages, $options); + } + /** * {@inheritdoc} */ @@ -33,7 +51,8 @@ class XliffFileDumper extends FileDumper $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2'); $xliffFile = $xliff->appendChild($dom->createElement('file')); - $xliffFile->setAttribute('source-language', $messages->getLocale()); + $xliffFile->setAttribute('source-language', $this->defaultLocale); + $xliffFile->setAttribute('target-language', $messages->getLocale()); $xliffFile->setAttribute('datatype', 'plaintext'); $xliffFile->setAttribute('original', 'file.ext'); diff --git a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php index bef31358c5..358f13f565 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php @@ -23,7 +23,7 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase $tempDir = sys_get_temp_dir(); $dumper = new XliffFileDumper(); - $dumper->dump($catalogue, array('path' => $tempDir)); + $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr')); $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en.xlf')); diff --git a/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf b/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf index 464b079200..3ab72eb110 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf +++ b/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf @@ -1,6 +1,6 @@ - + foo