Skip to content

Commit 9705855

Browse files
MarieMinasyannicolas-grekas
authored andcommitted
[Translation] Make name attribute optional in xliff2
Do not set a fake `name` attribute on `unit` element from xliff2 to allow using `source` attribute and avoid missing translation error
1 parent 56194a4 commit 9705855

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/Symfony/Component/Translation/Dumper/XliffFileDumper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ private function dumpXliff2(string $defaultLocale, MessageCatalogue $messages, ?
150150
foreach ($messages->all($domain) as $source => $target) {
151151
$translation = $dom->createElement('unit');
152152
$translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._'));
153-
$name = $source;
154-
if (\strlen($source) > 80) {
155-
$name = substr(md5($source), -7);
153+
154+
if (\strlen($source) <= 80) {
155+
$translation->setAttribute('name', $source);
156156
}
157-
$translation->setAttribute('name', $name);
157+
158158
$metadata = $messages->getMetadata($source, $domain);
159159

160160
// Add notes section

src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testFormatCatalogueXliff2()
4343
'foo' => 'bar',
4444
'key' => '',
4545
'key.with.cdata' => '<source> & <target>',
46+
'translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute' => 'value',
4647
]);
4748
$catalogue->setMetadata('key', ['target-attributes' => ['order' => 1]]);
4849

src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@
1919
<target><![CDATA[<source> & <target>]]></target>
2020
</segment>
2121
</unit>
22+
<unit id="aF1tx51">
23+
<segment>
24+
<source>translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute</source>
25+
<target>value</target>
26+
</segment>
27+
</unit>
2228
</file>
2329
</xliff>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy