8000 feature #45421 [Translation] Add the possibilty to export xliff tran… · symfony/symfony@c38a9bd · GitHub
[go: up one dir, main page]

Skip to content

Commit c38a9bd

Browse files
committed
feature #45421 [Translation] Add the possibilty to export xliff translation with the .xliff suffix (DanielBadura)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Translation] Add the possibilty to export xliff translation with the .xliff suffix | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Like the `YamlFileDumper` now the `XliffFileDumper` has the extension as an parameter. This enables the user to export xliff translation files with the suffix `.xlf` and `.xliff`. This is needed for example for the translation provider Lokalise and the GitLab integration for this provider. Commits ------- 08c4bc5 [Translation] Add the possibilty to export xliff translation with the .xliff suffix
2 parents 147a37f + 08c4bc5 commit c38a9bd

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Environment variable `SYMFONY_IDE` is read by default when `framework.ide` config is not set.
88
* Load PHP configuration files by default in the `MicroKernelTrait`
99
* Add `cache:pool:invalidate-tags` command
10+
* Add `XliffFileDumper` with `xliff` as the extension as a service
1011

1112
6.0
1213
---

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
->set('translation.dumper.xliff', XliffFileDumper::class)
115115
->tag('translation.dumper', ['alias' => 'xlf'])
116116

117+
->set('translation.dumper.xliff.xliff', XliffFileDumper::class)
118+
->args(['xliff'])
119+
->tag('translation.dumper', ['alias' => 'xliff'])
120+
117121
->set('translation.dumper.po', PoFileDumper::class)
118122
->tag('translation.dumper', ['alias' => 'po'])
119123

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

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

910
5.4
1011
---

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
*/
2222
class XliffFileDumper extends FileDumper
2323
{
24+
public function __construct(
25+
private string $extension = 'xlf',
26+
) {
27+
}
28+
2429
/**
2530
* {@inheritdoc}
2631
*/
@@ -52,7 +57,7 @@ public function formatCatalogue(MessageCatalogue $messages, string $domain, arra
5257
*/
5358
protected function getExtension(): string
5459
{
55-
return 'xlf';
60+
return $this->extension;
5661
}
5762

5863
private function dumpXliff1(string $defaultLocale, MessageCatalogue $messages, ?string $domain, array $options = [])

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,23 @@ public function testFormatCatalogueWithNotesMetadata()
128128
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
129129
);
130130
}
131+
132+
public function testDumpCatalogueWithXliffExtension()
133+
{
134+
$catalogue = new MessageCatalogue('en_US');
135+
$catalogue->add([
136+
'foo' => 'bar',
137+
'key' => '',
138+
'key.with.cdata' => '<source> & <target>',
139+
]);
140+
$catalogue->setMetadata('foo', ['notes' => [['priority' => 1, 'from' => 'bar', 'content' => 'baz']]]);
141+
$catalogue->setMetadata('key', ['notes' => [['content' => 'baz'], ['content' => 'qux']]]);
142+
143+
$dumper = new XliffFileDumper('xliff');
144+
145+
$this->assertStringEqualsFile(
146+
__DIR__.'/../fixtures/resources-clean.xliff',
147+
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR'])
148+
);
149+
}
131150
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
3+
<file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
4+
<header>
5+
<tool tool-id="symfony" tool-name="Symfony"/>
6+
</header>
7+
<body>
8+
<trans-unit id="LCa0a2j" resname="foo">
9+
<source>foo</source>
10+
<target>bar</target>
11+
<note priority="1" from="bar">baz</note>
12+
</trans-unit>
13+
<trans-unit id="LHDhK3o" resname="key">
14+
<source>key</source>
15+
<target></target>
16+
<note>baz</note>
17+
<note>qux</note>
18+
</trans-unit>
19+
<trans-unit id="2DA_bnh" resname="key.with.cdata">
20+
<source>key.with.cdata</source>
21+
<target><![CDATA[<source> & <target>]]></target>
22+
</trans-unit>
23+
</body>
24+
</file>
25+
</xliff>

0 commit comments

Comments
 (0)
0