Use XLIFF source rather than resname when there's no target

This commit is contained in:
Chris Wilkinson 2018-11-24 21:16:41 +00:00
parent e4a7fd8eed
commit 8633ebbca0
3 changed files with 5 additions and 2 deletions

View File

@ -90,7 +90,7 @@ class XliffFileLoader implements LoaderInterface
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $translation->source), $encoding);
$catalogue->set((string) $source, $target, $domain);

View File

@ -66,7 +66,7 @@ class XliffFileLoaderTest extends TestCase
$loader = new XliffFileLoader();
$catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1'));
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'), $catalogue->all('domain1'));
}
public function testIncompleteResource()

View File

@ -14,6 +14,9 @@
<source>baz</source>
<target>foo</target>
</trans-unit>
<trans-unit id="4" resname="qux">
<source>qux source</source>
</trans-unit>
</body>
</file>
</xliff>