From 8633ebbca0c6679d5f77f0cfae6659bf731741bf Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Sat, 24 Nov 2018 21:16:41 +0000 Subject: [PATCH] Use XLIFF source rather than resname when there's no target --- src/Symfony/Component/Translation/Loader/XliffFileLoader.php | 2 +- .../Component/Translation/Tests/Loader/XliffFileLoaderTest.php | 2 +- src/Symfony/Component/Translation/Tests/fixtures/resname.xlf | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index 4ad35decd1..1c7cba6ee8 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -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); diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index dc9a06bcb8..29bec0e612 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -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() diff --git a/src/Symfony/Component/Translation/Tests/fixtures/resname.xlf b/src/Symfony/Component/Translation/Tests/fixtures/resname.xlf index 2df16af942..4fa5c0017e 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/resname.xlf +++ b/src/Symfony/Component/Translation/Tests/fixtures/resname.xlf @@ -14,6 +14,9 @@ baz foo + + qux source +