8000 bug #30074 Fix wrong value in file id attribute for Xliff 2.0 (deguif) · symfony/symfony@0bb0c7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bb0c7f

Browse files
bug #30074 Fix wrong value in file id attribute for Xliff 2.0 (deguif)
This PR was squashed before being merged into the 4.2 branch (closes #30074). Discussion ---------- Fix wrong value in file id attribute for Xliff 2.0 | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | ? | Deprecations? | no | Tests pass? | ? | Fixed tickets | | License | MIT | Doc PR | Currently using the `XliffFileDumper` for exporting messages from catalogue with domain of the form `xxxx+intl-icu` produces an invalid Xliff version 2.0 file as the file id attribute is of type `xs:NMTOKEN` (cf. https://github.com/symfony/translation/blob/master/Resources/schemas/xliff-core-2.0.xsd#L139) which doesn't accept `+` character (cf. http://www.datypic.com/sc/xsd/t-xsd_NMTOKEN.html). Exception is thrown when loading the content after. Commits ------- 8bf12f8 Fix wrong value in file id attribute for Xliff 2.0
2 parents 2d66fe7 + 8bf12f8 commit 0bb0c7f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain,
141141
$xliff->setAttribute('trgLang', str_replace('_', '-', $messages->getLocale()));
142142

143143
$xliffFile = $xliff->appendChild($dom->createElement('file'));
144-
$xliffFile->setAttribute('id', $domain.'.'.$messages->getLocale());
144+
if (MessageCatalogue::INTL_DOMAIN_SUFFIX === substr($domain, -($suffixLength = \strlen(MessageCatalogue::INTL_DOMAIN_SUFFIX)))) {
145+
$xliffFile->setAttribute('id', substr($domain, 0, -$suffixLength).'.'.$messages->getLocale());
146+
} else {
147+
$xliffFile->setAttribute('id', $domain.'.'.$messages->getLocale());
148+
}
145149

146150
foreach ($messages->all($domain) as $source => $target) {
147151
$translation = $dom->createElement('unit');

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public function testFormatCatalogueXliff2()
5454
);
5555
}
5656

57+
public function testFormatIcuCatalogueXliff2()
58+
{
59+
$catalogue = new MessageCatalogue('en_US');
60+
$catalogue->add([
61+
'foo' => 'bar',
62+
], 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX);
63+
64+
$dumper = new XliffFileDumper();
65+
66+
$this->assertStringEqualsFile(
67+
__DIR__.'/../fixtures/resources-2.0+intl-icu.xlf',
68+
$dumper->formatCatalogue($catalogue, 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX, ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
69+
);
70+
}
71+
5772
public function testFormatCatalogueWithCustomToolInfo()
5873
{
5974
$options = [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US">
3+
<file id="messages.en_US">
4+
<unit id="LCa0a2j" name="foo">
5+
<segment>
6+
<source>foo</source>
7+
<target>bar</target>
8+
</segment>
9+
</unit>
10+
</file>
11+
</xliff>

0 commit comments

Comments
 (0)
0