Skip to content

Commit 1ee4a41

Browse files
committed
feature symfony#11371 [Translation:update][Xliff Dumper] added target-language. (aitboudad, ClementGautier)
This PR was merged into the 2.6-dev branch. Discussion ---------- [Translation:update][Xliff Dumper] added target-language. Q | A ------------ | ------------- Bug fix? | yes New feature? | yes BC breaks? | no Deprecations? | no Tests pass? | yes Fixed tickets | symfony#11218 License | MIT Complete this PR : symfony#11252 Commits ------- fdc3fb1 [Translation:update][Xliff Dumper] Reviewed code and replaced underscore by hyphen 1951412 [Translation:update][Xliff Dumper] added target-language.
2 parents e40e325 + fdc3fb1 commit 1ee4a41

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
150150
// save the files
151151
if ($input->getOption('force') === true) {
152152
$output->writeln('Writing files');
153-
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
153+
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
154154
}
155155
}
156156
}

src/Symfony/Component/Translation/Dumper/XliffFileDumper.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020
*/
2121
class XliffFileDumper extends FileDumper
2222
{
23+
/**
24+
* @var string
25+
*/
26+
private $defaultLocale;
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function dump(MessageCatalogue $messages, $options = array())
32+
{
33+
if (array_key_exists('default_locale', $options)) {
34+
$this->defaultLocale = $options['default_locale'];
35+
} else {
36+
$this->defaultLocale = \Locale::getDefault();
37+
}
38+
39+
parent::dump($messages, $options);
40+
}
41+
2342
/**
2443
* {@inheritdoc}
2544
*/
@@ -33,7 +52,8 @@ protected function format(MessageCatalogue $messages, $domain)
3352
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
3453

3554
$xliffFile = $xliff->appendChild($dom->createElement('file'));
36-
$xliffFile->setAttribute('source-language', $messages->getLocale());
55+
$xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale));
56+
$xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
3757
$xliffFile->setAttribute('datatype', 'plaintext');
3858
$xliffFile->setAttribute('original', 'file.ext');
3959

src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
1818
{
1919
public function testDump()
2020
{
21-
$catalogue = new MessageCatalogue('en');
21+
$catalogue = new MessageCatalogue('en_US');
2222
$catalogue->add(array('foo' => 'bar', 'key' => ''));
2323
$catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz'))));
2424
$catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux'))));
2525

2626
$tempDir = sys_get_temp_dir();
2727
$dumper = new XliffFileDumper();
28-
$dumper->dump($catalogue, array('path' => $tempDir));
28+
$dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR'));
2929

30-
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en.xlf'));
30+
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en_US.xlf'));
3131

32-
unlink($tempDir.'/messages.en.xlf');
32+
unlink($tempDir.'/messages.en_US.xlf');
3333
}
3434
}

src/Symfony/Component/Translation/Tests/fixtures/resources-clean.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
3-
<file source-language="en" datatype="plaintext" original="file.ext">
3+
<file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
44
<body>
55
<trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
66
<source>foo</source>

0 commit comments

Comments
 (0)