Support omitting the <target> node in an .xlf file.
This commit is contained in:
parent
cca29d849a
commit
3dcda1a8bd
@ -48,12 +48,12 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
||||||
$attributes = $translation->attributes();
|
$attributes = $translation->attributes();
|
||||||
|
|
||||||
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
|
if (!(isset($attributes['resname']) || isset($translation->source))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
|
$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
|
// If the xlf file has another encoding specified, try to convert it because
|
||||||
// simple_xml will always return utf-8 encoded values
|
// simple_xml will always return utf-8 encoded values
|
||||||
|
@ -55,8 +55,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => 'bar', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
|
$this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
|
||||||
$this->assertFalse($catalogue->has('extra', 'domain1'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEncoding()
|
public function testEncoding()
|
||||||
|
Reference in New Issue
Block a user