Skip to content

[Translation] Add the possibilty to export xliff translation with the .xliff suffix #45421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Environment variable `SYMFONY_IDE` is read by default when `framework.ide` config is not set.
* Load PHP configuration files by default in the `MicroKernelTrait`
* Add `cache:pool:invalidate-tags` command
* Add `XliffFileDumper` with `xliff` as the extension as a service

6.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
->set('translation.dumper.xliff', XliffFileDumper::class)
->tag('translation.dumper', ['alias' => 'xlf'])

->set('translation.dumper.xliff.xliff', XliffFileDumper::class)
->args(['xliff'])
->tag('translation.dumper', ['alias' => 'xliff'])

->set('translation.dumper.po', PoFileDumper::class)
->tag('translation.dumper', ['alias' => 'po'])

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Parameters implementing `TranslatableInterface` are processed
* `XliffFileDumper` can now be instantiated with the extension for example `xliff`

5.4
---
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Translation/Dumper/XliffFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
class XliffFileDumper extends FileDumper
{
public function __construct(
private string $extension = 'xlf',
) {
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -52,7 +57,7 @@ public function formatCatalogue(MessageCatalogue $messages, string $domain, arra
*/
protected function getExtension(): string
{
return 'xlf';
return $this->extension;
}

private function dumpXliff1(string $defaultLocale, MessageCatalogue $messages, ?string $domain, array $options = [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,23 @@ public function testFormatCatalogueWithNotesMetadata()
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
);
}

public function testDumpCatalogueWithXliffExtension()
{
$catalogue = new MessageCatalogue('en_US');
$catalogue->add([
'foo' => 'bar',
'key' => '',
'key.with.cdata' => '<source> & <target>',
]);
$catalogue->setMetadata('foo', ['notes' => [['priority' => 1, 'from' => 'bar', 'content' => 'baz']]]);
$catalogue->setMetadata('key', ['notes' => [['content' => 'baz'], ['content' => 'qux']]]);

$dumper = new XliffFileDumper('xliff');

$this->assertStringEqualsFile(
__DIR__.'/../fixtures/resources-clean.xliff',
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR'])
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="LCa0a2j" resname="foo">
<source>foo</source>
<target>bar</target>
<note priority="1" from="bar">baz</note>
</trans-unit>
<trans-unit id="LHDhK3o" resname="key">
<source>key</source>
<target></target>
<note>baz</note>
<note>qux</note>
</trans-unit>
<trans-unit id="2DA_bnh" resname="key.with.cdata">
<source>key.with.cdata</source>
<target><![CDATA[<source> & <target>]]></target>
</trans-unit>
</body>
</file>
</xliff>