Skip to content

Commit d598cae

Browse files
Merge branch '3.4'
* 3.4: [Webprofiler] Added blocks that allows extension of the profiler page. [Dotenv] Get env using $_SERVER to work with fastcgi_param and workaround thread safety issues [Dotenv][WebServerBundle] Override previously loaded variables Create an interface for TranslationWriter [Translation] Adding the ability do dump <notes> in xliff2.0 [DI] Use GlobResource for non-tracked directories [DI] Fix resolving env vars when compiling a ContainerBuilder [SecurityBundle] resolve class name parameter inside AddSecurityVotersPass [FrameworkBundle] Add soft conflict rule of "cache:clear" + HttpKernel 3.4 [WebProfilerBundle] Re add missing link to the controller
2 parents d4f6b88 + f8b9847 commit d598cae

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG
1212
* Added `TranslationDumperPass`
1313
* Added `TranslationExtractorPass`
1414
* Added `TranslatorPass`
15+
* Added <notes> section to the Xliff 2.0 dumper.
16+
* Added `TranslationWriterInterface`
17+
* Deprecated `TranslationWriter::writeTranslations` in favor of `TranslationWriter::write`
1518

1619
3.2.0
1720
-----

Dumper/XliffFileDumper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain,
146146
foreach ($messages->all($domain) as $source => $target) {
147147
$translation = $dom->createElement('unit');
148148
$translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._'));
149+
$metadata = $messages->getMetadata($source, $domain);
150+
151+
// Add notes section
152+
if ($this->hasMetadataArrayInfo('notes', $metadata)) {
153+
$notesElement = $dom->createElement('notes');
154+
foreach ($metadata['notes'] as $note) {
155+
$n = $dom->createElement('note');
156+
$n->appendChild($dom->createTextNode(isset($note['content']) ? $note['content'] : ''));
157+
unset($note['content']);
158+
159+
foreach ($note as $name => $value) {
160+
$n->setAttribute($name, $value);
161+
}
162+
$notesElement->appendChild($n);
163+
}
164+
$translation->appendChild($notesElement);
165+
}
149166

150167
$segment = $translation->appendChild($dom->createElement('segment'));
151168

@@ -156,7 +173,6 @@ private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain,
156173
$text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
157174

158175
$targetElement = $dom->createElement('target');
159-
$metadata = $messages->getMetadata($source, $domain);
160176
if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
161177
foreach ($metadata['target-attributes'] as $name => $value) {
162178
$targetElement->setAttribute($name, $value);

Tests/Dumper/XliffFileDumperTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,24 @@ public function testFormatCatalogueWithTargetAttributesMetadata()
8787
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
8888
);
8989
}
90+
91+
public function testFormatCatalogueWithNotesMetadata()
92+
{
93+
$catalogue = new MessageCatalogue('en_US');
94+
$catalogue->add(array(
95+
'foo' => 'bar',
96+
));
97+
$catalogue->setMetadata('foo', array('notes' => array(
98+
array('category' => 'state', 'content' => 'new'),
99+
array('category' => 'approved', 'content' => 'true'),
100+
array('category' => 'section', 'content' => 'user login', 'priority' => '1'),
101+
)));
102+
103+
$dumper = new XliffFileDumper();
104+
105+
$this->assertStringEqualsFile(
106+
__DIR__.'/../fixtures/resources-notes-meta.xlf',
107+
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
108+
);
109+
}
90110
}

Tests/Writer/TranslationWriterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
class TranslationWriterTest extends TestCase
2020
{
21+
/**
22+
* @group legacy
23+
* @expectedDeprecation Method Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations() is deprecated since version 3.4 and will be removed in 4.0. Use write() instead.
24+
*/
2125
public function testWriteTranslations()
2226
{
2327
$dumper = $this->getMockBuilder('Symfony\Component\Translation\Dumper\DumperInterface')->getMock();
@@ -30,6 +34,18 @@ public function testWriteTranslations()
3034
$writer->writeTranslations(new MessageCatalogue(array()), 'test');
3135
}
3236

37+
public function testWrite()
38+
{
39+
$dumper = $this->getMockBuilder('Symfony\Component\Translation\Dumper\DumperInterface')->getMock();
40+
$dumper
41+
->expects($this->once())
42+
->method('dump');
43+
44+
$writer = new TranslationWriter();
45+
$writer->addDumper('test', $dumper);
46+
$writer->write(new MessageCatalogue(array()), 'test');
47+
}
48+
3349
public function testDisableBackup()
3450
{
3551
$nonBackupDumper = new NonBackupDumper();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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">
5+
<notes>
6+
<note category="state">new</note>
7+
<note category="approved">true</note>
8+
<note category="section" priority="1">user login</note>
9+
</notes>
10+
<segment>
11+
<source>foo</source>
12+
<target>bar</target>
13+
</segment>
14+
</unit>
15+
</file>
16+
</xliff>

Writer/TranslationWriter.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Michel Salib <[email protected]>
2323
*/
24-
class TranslationWriter
24+
class TranslationWriter implements TranslationWriterInterface
2525
{
2626
/**
2727
* Dumpers used for export.
@@ -67,13 +67,13 @@ public function getFormats()
6767
/**
6868
* Writes translation from the catalogue according to the selected format.
6969
*
70-
* @param MessageCatalogue $catalogue The message catalogue to dump
70+
* @param MessageCatalogue $catalogue The message catalogue to write
7171
* @param string $format The format to use to dump the messages
7272
* @param array $options Options that are passed to the dumper
7373
*
7474
* @throws InvalidArgumentException
7575
*/
76-
public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array())
76+
public function write(MessageCatalogue $catalogue, $format, $options = array())
7777
{
7878
if (!isset($this->dumpers[$format])) {
7979
throw new InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
@@ -89,4 +89,21 @@ public function writeTranslations(MessageCatalogue $catalogue, $format, $options
8989
// save
9090
$dumper->dump($catalogue, $options);
9191
}
92+
93+
/**
94+
* Writes translation from the catalogue according to the selected format.
95+
*
96+
* @param MessageCatalogue $catalogue The message catalogue to write
97+
* @param string $format The format to use to dump the messages
98+
* @param array $options Options that are passed to the dumper
99+
*
100+
* @throws InvalidArgumentException
101+
*
102+
* @deprecated since 3.4 will be removed in 4.0. Use write instead.
103+
*/
104+
public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array())
105+
{
106+
@trigger_error(sprintf('Method %s() is deprecated since version 3.4 and will be removed in 4.0. Use write() instead.', __METHOD__), E_USER_DEPRECATED);
107+
$this->write($catalogue, $format, $options);
108+
}
92109
}

Writer/TranslationWriterInterface.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Writer;
13+
14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
use Symfony\Component\Translation\MessageCatalogue;
16+
17+
/**
18+
* TranslationWriter writes translation messages.
19+
*
20+
* @author Michel Salib <[email protected]>
21+
*/
22+
interface TranslationWriterInterface
23+
{
24+
/**
25+
* Writes translation from the catalogue according to the selected format.
26+
*
27+
* @param MessageCatalogue $catalogue The message catalogue to write
28+
* @param string $format The format to use to dump the messages
29+
* @param array $options Options that are passed to the dumper
30+
*
31+
* @throws InvalidArgumentException
32+
*/
33+
public function write(MessageCatalogue $catalogue, $format, $options = array());
34+
}

0 commit comments

Comments
 (0)