Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc7b54d

Browse files
bug #54564 [Translation] Skip state=needs-translation entries only when source == target (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [Translation] Skip state=needs-translation entries only when source == target | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54541 | License | MIT Commits ------- 155d23f [Translation] Skip state=needs-translation entries only when source == target
2 parents 21026a1 + 155d23f commit dc7b54d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,20 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, s
111111
continue;
112112
}
113113

114-
if (isset($translation->target) && 'needs-translation' === (string) $translation->target->attributes()['state']) {
114+
$source = (string) (isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source);
115+
116+
if (isset($translation->target)
117+
&& 'needs-translation' === (string) $translation->target->attributes()['state']
118+
&& \in_array((string) $translation->target, [$source, (string) $translation->source], true)
119+
) {
115120
continue;
116121
}
117122

118-
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
119123
// If the xlf file has another encoding specified, try to convert it because
120124
// simple_xml will always return utf-8 encoded values
121125
$target = $this->utf8ToCharset((string) ($translation->target ?? $translation->source), $encoding);
122126

123-
$catalogue->set((string) $source, $target, $domain);
127+
$catalogue->set($source, $target, $domain);
124128

125129
$metadata = [
126130
'source' => (string) $translation->source,
@@ -143,7 +147,7 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, s
143147
$metadata['id'] = (string) $attributes['id'];
144148
}
145149

146-
$catalogue->setMetadata((string) $source, $metadata, $domain);
150+
$catalogue->setMetadata($source, $metadata, $domain);
147151
}
148152
}
149153
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ public function testLoadRawXliff()
5252
</trans-unit>
5353
<trans-unit id="4">
5454
<source>test</source>
55-
<target>with</target>
55+
<target state="needs-translation">with</target>
5656
<note>note</note>
5757
</trans-unit>
58+
<trans-unit id="5">
59+
<source>baz</source>
60+
<target state="needs-translation">baz</target>
61+
</trans-unit>
62+
<trans-unit id="6" resname="buz">
63+
<source>baz</source>
64+
<target state="needs-translation">buz</target>
65+
</trans-unit>
5866
</body>
5967
</file>
6068
</xliff>
@@ -65,6 +73,7 @@ public function testLoadRawXliff()
6573
$this->assertEquals('en', $catalogue->getLocale());
6674
$this->assertSame([], libxml_get_errors());
6775
$this->assertContainsOnly('string', $catalogue->all('domain1'));
76+
$this->assertSame(['foo', 'extra', 'key', 'test'], array_keys($catalogue->all('domain1')));
6877
}
6978

7079
public function testLoadWithInternalErrorsEnabled()

0 commit comments

Comments
 (0)