[Translation] Ignore xliff entries with no "target" node
This commit is contained in:
parent
69fc07a21c
commit
93d2a4f039
15
resources-clean.xlf
Normal file
15
resources-clean.xlf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?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">
|
||||||
|
<body>
|
||||||
|
<trans-unit id="1">
|
||||||
|
<source>foo</source>
|
||||||
|
<target>bar</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="2">
|
||||||
|
<source>key</source>
|
||||||
|
<target></target>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
@ -39,6 +39,9 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
|
|
||||||
$catalogue = new MessageCatalogue($locale);
|
$catalogue = new MessageCatalogue($locale);
|
||||||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
||||||
|
if (2 !== count($translation)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$catalogue->set((string) $translation->source, (string) $translation->target, $domain);
|
$catalogue->set((string) $translation->source, (string) $translation->target, $domain);
|
||||||
}
|
}
|
||||||
$catalogue->addResource(new FileResource($resource));
|
$catalogue->addResource(new FileResource($resource));
|
||||||
|
@ -19,13 +19,13 @@ 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'));
|
$catalogue->add(array('foo' => 'bar', 'key' => ''));
|
||||||
|
|
||||||
$tempDir = sys_get_temp_dir();
|
$tempDir = sys_get_temp_dir();
|
||||||
$dumper = new XliffFileDumper();
|
$dumper = new XliffFileDumper();
|
||||||
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
|
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
|
||||||
|
|
||||||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.xlf'), file_get_contents($tempDir.'/messages.en.xlf'));
|
$this->assertEquals(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');
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,19 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resource = __DIR__.'/../fixtures/resources.xlf';
|
$resource = __DIR__.'/../fixtures/resources.xlf';
|
||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIncompleteResource()
|
||||||
|
{
|
||||||
|
$loader = new XliffFileLoader();
|
||||||
|
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
|
$this->assertEquals(array('foo' => 'bar', 'key' => ''), $catalogue->all('domain1'));
|
||||||
|
$this->assertFalse($catalogue->has('extra', 'domain1'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
<source>foo</source>
|
<source>foo</source>
|
||||||
<target>bar</target>
|
<target>bar</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="2">
|
||||||
|
<source>extra</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="3">
|
||||||
|
<source>key</source>
|
||||||
|
<target></target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
Reference in New Issue
Block a user