[Translation] made XliffFileDumper support CDATA sections.
This commit is contained in:
parent
cd005e69ff
commit
9926845cf3
|
@ -47,8 +47,13 @@ class XliffFileDumper extends FileDumper
|
||||||
$s = $translation->appendChild($dom->createElement('source'));
|
$s = $translation->appendChild($dom->createElement('source'));
|
||||||
$s->appendChild($dom->createTextNode($source));
|
$s->appendChild($dom->createTextNode($source));
|
||||||
|
|
||||||
|
// Does the target contain characters requiring a CDATA section?
|
||||||
|
$text = (1 === preg_match('/[&<>]/', $target))
|
||||||
|
? $dom->createCDATASection($target)
|
||||||
|
: $dom->createTextNode($target);
|
||||||
|
|
||||||
$t = $translation->appendChild($dom->createElement('target'));
|
$t = $translation->appendChild($dom->createElement('target'));
|
||||||
$t->appendChild($dom->createTextNode($target));
|
$t->appendChild($text);
|
||||||
|
|
||||||
$xliffBody->appendChild($translation);
|
$xliffBody->appendChild($translation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,20 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$catalogue = new MessageCatalogue('en');
|
$catalogue = new MessageCatalogue('en');
|
||||||
$catalogue->add(array('foo' => 'bar', 'key' => ''));
|
$catalogue->add(array(
|
||||||
|
'foo' => 'bar',
|
||||||
|
'key' => '',
|
||||||
|
'key.with.cdata' => '<source> & <target>',
|
||||||
|
));
|
||||||
|
|
||||||
$tempDir = sys_get_temp_dir();
|
$tempDir = sys_get_temp_dir();
|
||||||
$dumper = new XliffFileDumper();
|
$dumper = new XliffFileDumper();
|
||||||
$dumper->dump($catalogue, array('path' => $tempDir));
|
$dumper->dump($catalogue, array('path' => $tempDir));
|
||||||
|
|
||||||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en.xlf'));
|
$this->assertSame(
|
||||||
|
file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'),
|
||||||
|
file_get_contents($tempDir.'/messages.en.xlf')
|
||||||
|
);
|
||||||
|
|
||||||
unlink($tempDir.'/messages.en.xlf');
|
unlink($tempDir.'/messages.en.xlf');
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
<source>key</source>
|
<source>key</source>
|
||||||
<target></target>
|
<target></target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="18e6a493872558d949b4c16ea1fa6ab6" resname="key.with.cdata">
|
||||||
|
<source>key.with.cdata</source>
|
||||||
|
<target><![CDATA[<source> & <target>]]></target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Reference in New Issue