Skip to content

Commit ac4bf86

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: (39 commits) fix merge add missing return type-hints fix merge explicitly mark nullable parameters as nullable fix low deps tests [HttpKernel] Fix datacollector caster for reference object property [Serializer] Fixing PHP warning in the ObjectNormalizer with MaxDepth enabled bug #51578 [Cache] always select database for persistent redis connections [Security] Validate that CSRF token in form login is string similar to username/password [Serializer] Use explicit nullable type [validator] validated Dutch translation Improve dutch translations initialize the current time with midnight before modifying the date [Translation] Skip state=needs-translation entries only when source == target [HttpKernel] Ensure controllers are not lazy [Validator] Fill in trans-unit id 113: This URL does not contain a TLD. [Validator] added missing Polish translation for unit 113 [Validator] add missing lv translation fix tests [HttpClient] Let curl handle transfer encoding ...
2 parents 48f4596 + a9ed676 commit ac4bf86

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Loader/XliffFileLoader.php

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

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

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

124-
$catalogue->set((string) $source, $target, $domain);
128+
$catalogue->set($source, $target, $domain);
125129

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

147-
$catalogue->setMetadata((string) $source, $metadata, $domain);
151+
$catalogue->setMetadata($source, $metadata, $domain);
148152
}
149153
}
150154
}

Resources/bin/translation-status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function extractTranslationKeys($filePath): array
166166

167167
foreach ($contents->file->body->{'trans-unit'} as $translationKey) {
168168
$translationId = (string) $translationKey['id'];
169-
$translationKey = (string) $translationKey->source;
169+
$translationKey = (string) ($translationKey['resname'] ?? $translationKey->source);
170170

171171
$translationKeys[$translationId] = $translationKey;
172172
}

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)