Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 155d23f

Browse filesBrowse files
[Translation] Skip state=needs-translation entries only when source == target
1 parent 3faeb57 commit 155d23f
Copy full SHA for 155d23f

File tree

2 files changed

+18
-5
lines changed
Filter options

2 files changed

+18
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Loader/XliffFileLoader.php
+8-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php
+10-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.