Support omitting the <target> node in an .xlf file.

This commit is contained in:
Leo Feyer 2015-08-24 21:18:54 +02:00 committed by Abdellatif Ait boudad
parent cca29d849a
commit 3dcda1a8bd
2 changed files with 3 additions and 4 deletions

View File

@ -48,12 +48,12 @@ class XliffFileLoader implements LoaderInterface
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$attributes = $translation->attributes();
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
if (!(isset($attributes['resname']) || isset($translation->source))) {
continue;
}
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
$target = (string) $translation->target;
$target = (string) isset($translation->target) ? $translation->target : $source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values

View File

@ -55,8 +55,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' => '', 'test' => 'with'), $catalogue->all('domain1'));
$this->assertFalse($catalogue->has('extra', 'domain1'));
$this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
}
public function testEncoding()