8000 bug #29308 [Translation] Use XLIFF source rather than resname when th… · symfony/symfony@c0bfdeb · GitHub
[go: up one dir, main page]

Skip to content

Commit c0bfdeb

Browse files
committed
bug #29308 [Translation] Use XLIFF source rather than resname when there's no target (thewilkybarkid)
This PR was merged into the 2.8 branch. Discussion ---------- [Translation] Use XLIFF source rather than resname when there's no target | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Relates to #20076 (comment). If there's no `<target>` in an XLIFF but there is a `@resname` then that's used rather than the `<source>`. If I'm using translation keys and my source locale is `en`, then it's a bit redundant to duplicate the `<source>` in the `<target>` in the `en` file (since there is no translation). This isn't changing the behaviour when `<target>` is present but empty. (Caveat: I'm definitely not an expert on XLIFF.) Commits ------- 8633ebb Use XLIFF source rather than resname when there's no target
2 parents 8a60f98 + 8633ebb commit c0bfdeb

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
9090
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->sou 8000 rce;
9191
// If the xlf file has another encoding specified, try to convert it because
9292
// simple_xml will always return utf-8 encoded values
93-
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
93+
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $translation->source), $encoding);
9494

9595
$catalogue->set((string) $source, $target, $domain);
9696

src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testLoadWithResname()
6666
$loader = new XliffFileLoader();
6767
$catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
6868

69-
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1'));
69+
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'), $catalogue->all('domain1'));
7070
}
7171

7272
public function testIncompleteResource()

src/Symfony/Component/Translation/Tests/fixtures/resname.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<source>baz</source>
1515
<target>foo</target>
1616
</trans-unit>
17+
<trans-unit id="4" resname="qux">
18+
<source>qux source</source>
19+
</trans-unit>
1720
</body>
1821
</file>
1922
</xliff>

0 commit comments

Comments
 (0)
0