Skip to content

Commit 2ae1c3c

Browse files
Nyholmnicolas-grekas
authored andcommitted
Create an interface for TranslationWriter
1 parent 62bb068 commit 2ae1c3c

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CHANGELOG
77
* Added `TranslationDumperPass`
88
* Added `TranslationExtractorPass`
99
* Added `TranslatorPass`
10+
* Added `TranslationWriterInterface`
11+
* Deprecated `TranslationWriter::writeTranslations` in favor of `TranslationWriter::write`
1012

1113
3.2.0
1214
-----

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();

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.
@@ -66,13 +66,13 @@ public function getFormats()
6666
/**
6767
* Writes translation from the catalogue according to the selected format.
6868
*
69-
* @param MessageCatalogue $catalogue The message catalogue to dump
69+
* @param MessageCatalogue $catalogue The message catalogue to write
7070
* @param string $format The format to use to dump the messages
7171
* @param array $options Options that are passed to the dumper
7272
*
7373
* @throws InvalidArgumentException
7474
*/
75-
public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array())
75+
public function write(MessageCatalogue $catalogue, $format, $options = array())
7676
{
7777
if (!isset($this->dumpers[$format])) {
7878
throw new InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
@@ -88,4 +88,21 @@ public function writeTranslations(MessageCatalogue $catalogue, $format, $options
8888
// save
8989
$dumper->dump($catalogue, $options);
9090
}
91+
92+
/**
93+
* Writes translation from the catalogue according to the selected format.
94+
*
95+
* @param MessageCatalogue $catalogue The message catalogue to write
96+
* @param string $format The format to use to dump the messages
97+
* @param array $options Options that are passed to the dumper
98+
*
99+
* @throws InvalidArgumentException
100+
*
101+
* @deprecated since 3.4 will be removed in 4.0. Use write instead.
102+
*/
103+
public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array())
104+
{
105+
@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);
106+
$this->write($catalogue, $format, $options);
107+
}
91108
}

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)