diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 8457656f08..5afc9b45e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -150,7 +150,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 bd9b01255e..32a9c6b92b 100644 --- a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php @@ -20,6 +20,25 @@ use Symfony\Component\Translation\MessageCatalogue; */ class XliffFileDumper extends FileDumper { + /** + * @var string + */ + private $defaultLocale; + + /** + * {@inheritdoc} + */ + public function dump(MessageCatalogue $messages, $options = array()) + { + if (array_key_exists('default_locale', $options)) { + $this->defaultLocale = $options['default_locale']; + } else { + $this->defaultLocale = \Locale::getDefault(); + } + + parent::dump($messages, $options); + } + /** * {@inheritdoc} */ @@ -33,7 +52,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', str_replace('_', '-', $this->defaultLocale)); + $xliffFile->setAttribute('target-language', str_replace('_', '-', $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 daf0f7a37d..1335512bf1 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php @@ -18,17 +18,17 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase { public function testDump() { - $catalogue = new MessageCatalogue('en'); + $catalogue = new MessageCatalogue('en_US'); $catalogue->add(array('foo' => 'bar', 'key' => '')); $catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz')))); $catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux')))); $tempDir = sys_get_temp_dir(); $dumper = new XliffFileDumper(); - $dumper->dump($catalogue, array('path' => $tempDir)); + $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR')); - $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en.xlf')); + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en_US.xlf')); - unlink($tempDir.'/messages.en.xlf'); + unlink($tempDir.'/messages.en_US.xlf'); } } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf b/src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf index 3c38d3d19a..3898821804 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