Skip to content

Commit

Permalink
bug #11513 [Translation] made XliffFileDumper support CDATA sections.…
Browse files Browse the repository at this point in the history
… (hhamon)

This PR was merged into the 2.3 branch.

Discussion
----------

[Translation] made XliffFileDumper support CDATA sections.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | maybe
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11256
| License       | MIT

Commits
-------

9926845 [Translation] made XliffFileDumper support CDATA sections.
  • Loading branch information
fabpot committed Sep 16, 2014
2 parents f776e0c + 9926845 commit 036726c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Symfony/Component/Translation/Dumper/XliffFileDumper.php
Expand Up @@ -47,8 +47,13 @@ protected function format(MessageCatalogue $messages, $domain)
$s = $translation->appendChild($dom->createElement('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->appendChild($dom->createTextNode($target));
$t->appendChild($text);

$xliffBody->appendChild($translation);
}
Expand Down
Expand Up @@ -19,13 +19,20 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
public function testDump()
{
$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();
$dumper = new XliffFileDumper();
$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');
}
Expand Down
Expand Up @@ -10,6 +10,10 @@
<source>key</source>
<target></target>
</trans-unit>
<trans-unit id="18e6a493872558d949b4c16ea1fa6ab6" resname="key.with.cdata">
<source>key.with.cdata</source>
<target><![CDATA[<source> & <target>]]></target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 036726c

Please sign in to comment.