merged branch xkobal/2.1 (PR #6079)

This PR was squashed before being merged into the 2.1 branch (closes #6079).

Commits
-------

bbeff54 Xliff with other node than source or target are ignored

Discussion
----------

Xliff with other node than source or target are ignored

Referring to the xliff XSD, the format can allow other nodes like <note>. Check only count is dangerous if others nodes are present, and we aren't sure that nodes are the two we wan't (source and target)

And the real problem if that if there is other node in translation, the translation is silently ignored.

---------------------------------------------------------------------------

by stloyd at 2012-11-20T17:44:47Z

You should add test that covers this, as well as #6078 should be closed (branch `2.1` is merged from time to time to `master`).

---------------------------------------------------------------------------

by xkobal at 2012-11-21T11:13:32Z

I have added a new node to xliff fixtures and edit test to be sure node isn't ignored.
This commit is contained in:
Fabien Potencier 2012-11-21 16:37:43 +01:00
commit aa12428867
3 changed files with 7 additions and 2 deletions

View File

@ -39,7 +39,7 @@ class XliffFileLoader implements LoaderInterface
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
if (2 !== count($translation)) {
if (!isset($translation->source) || !isset($translation->target)) {
continue;
}
$catalogue->set((string) $translation->source, (string) $translation->target, $domain);

View File

@ -38,7 +38,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new XliffFileLoader();
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar', 'key' => ''), $catalogue->all('domain1'));
$this->assertEquals(array('foo' => 'bar', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
$this->assertFalse($catalogue->has('extra', 'domain1'));
}

View File

@ -13,6 +13,11 @@
<source>key</source>
<target></target>
</trans-unit>
<trans-unit id="4">
<source>test</source>
<target>with</target>
<note>note</note>
</trans-unit>
</body>
</file>
</xliff>