feature #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 | #11218 License | MIT Complete this PR : https://github.com/symfony/symfony/pull/11252 Commits -------fdc3fb1
[Translation:update][Xliff Dumper] Reviewed code and replaced underscore by hyphen1951412
[Translation:update][Xliff Dumper] added target-language.
This commit is contained in:
commit
1ee4a41783
@ -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')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
|
||||
<file source-language="en" datatype="plaintext" original="file.ext">
|
||||
<file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
|
||||
<body>
|
||||
<trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
|
||||
<source>foo</source>
|
||||
|
Reference in New Issue
Block a user