From 707c3d7632004fa3b6f2a3b5f1e3ebb9993d5e3f Mon Sep 17 00:00:00 2001 From: David Vancl <43696921+davidvancl@users.noreply.github.com> Date: Tue, 11 Feb 2025 09:36:58 +0100 Subject: [PATCH] [Translation] check empty notes --- .../Translation/Dumper/XliffFileDumper.php | 2 +- .../Tests/Dumper/XliffFileDumperTest.php | 36 +++++++++++++++++++ .../Fixtures/resources-2.0-empty-notes.xlf | 20 +++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Translation/Tests/Fixtures/resources-2.0-empty-notes.xlf diff --git a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php index d0f016b23c365..f5ce96a02580c 100644 --- a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php @@ -176,7 +176,7 @@ private function dumpXliff2(string $defaultLocale, MessageCatalogue $messages, ? $metadata = $messages->getMetadata($source, $domain); // Add notes section - if ($this->hasMetadataArrayInfo('notes', $metadata)) { + if ($this->hasMetadataArrayInfo('notes', $metadata) && $metadata['notes']) { $notesElement = $dom->createElement('notes'); foreach ($metadata['notes'] as $note) { $n = $dom->createElement('note'); diff --git a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php index f9ae8986f52fe..a1a125f605880 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php @@ -147,4 +147,40 @@ public function testDumpCatalogueWithXliffExtension() $dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR']) ); } + + public function testFormatCatalogueXliff2WithSegmentAttributes() + { + $catalogue = new MessageCatalogue('en_US'); + $catalogue->add([ + 'foo' => 'bar', + 'key' => '', + ]); + $catalogue->setMetadata('foo', ['segment-attributes' => ['state' => 'translated']]); + $catalogue->setMetadata('key', ['segment-attributes' => ['state' => 'translated', 'subState' => 'My Value']]); + + $dumper = new XliffFileDumper(); + + $this->assertStringEqualsFile( + __DIR__.'/../Fixtures/resources-2.0-segment-attributes.xlf', + $dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0']) + ); + } + + public function testEmptyMetadataNotes() + { + $catalogue = new MessageCatalogue('en_US'); + $catalogue->add([ + 'empty' => 'notes', + 'full' => 'notes', + ]); + $catalogue->setMetadata('empty', ['notes' => []]); + $catalogue->setMetadata('full', ['notes' => [['category' => 'file-source', 'priority' => 1, 'content' => 'test/path/to/translation/Example.1.html.twig:27']]]); + + $dumper = new XliffFileDumper(); + + $this->assertStringEqualsFile( + __DIR__.'/../Fixtures/resources-2.0-empty-notes.xlf', + $dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0']) + ); + } } diff --git a/src/Symfony/Component/Translation/Tests/Fixtures/resources-2.0-empty-notes.xlf b/src/Symfony/Component/Translation/Tests/Fixtures/resources-2.0-empty-notes.xlf new file mode 100644 index 0000000000000..7cba2cc09b41e --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/Fixtures/resources-2.0-empty-notes.xlf @@ -0,0 +1,20 @@ + + + + + + empty + notes + + + + + test/path/to/translation/Example.1.html.twig:27 + + + full + notes + + + + 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