Skip to content

Commit

Permalink
bug #30074 Fix wrong value in file id attribute for Xliff 2.0 (deguif)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolas-grekas committed Feb 7, 2019
2 parents 2d66fe7 + 8bf12f8 commit 0bb0c7f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/Translation/Dumper/XliffFileDumper.php
Expand Up @@ -141,7 +141,11 @@ private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain,
$xliff->setAttribute('trgLang', str_replace('_', '-', $messages->getLocale()));

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

foreach ($messages->all($domain) as $source => $target) {
$translation = $dom->createElement('unit');
Expand Down
Expand Up @@ -54,6 +54,21 @@ public function testFormatCatalogueXliff2()
);
}

public function testFormatIcuCatalogueXliff2()
{
$catalogue = new MessageCatalogue('en_US');
$catalogue->add([
'foo' => 'bar',
], 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX);

$dumper = new XliffFileDumper();

$this->assertStringEqualsFile(
__DIR__.'/../fixtures/resources-2.0+intl-icu.xlf',
$dumper->formatCatalogue($catalogue, 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX, ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
);
}

public function testFormatCatalogueWithCustomToolInfo()
{
$options = [
Expand Down
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US">
<file id="messages.en_US">
<unit id="LCa0a2j" name="foo">
<segment>
<source>foo</source>
<target>bar</target>
</segment>
</unit>
</file>
</xliff>

0 comments on commit 0bb0c7f

Please sign in to comment.