Skip to content

Commit cf1ff43

Browse files
feature symfony#23665 Create an interface for TranslationWriter (Nyholm)
This PR was squashed before being merged into the 3.4 branch (closes symfony#23665). Discussion ---------- Create an interface for TranslationWriter | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | ~~~no~~~ yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | We should provide an interface for the TranslationWriter. This allows other libraries (php-translation) that depend on the Translation component provide different implementations. Commits ------- c25eafa Create an interface for TranslationWriter
2 parents b2fea88 + c25eafa commit cf1ff43

File tree

7 files changed

+89
-10
lines changed

7 files changed

+89
-10
lines changed

UPGRADE-3.4.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ SecurityBundle
160160

161161
* `FirewallContext::getListeners()` now returns `\Traversable|array`
162162

163+
Translation
164+
-----------
165+
166+
* `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations` has been deprecated
167+
and will be removed in 4.0, use `Symfony\Component\Translation\Writer\TranslationWriter::write`
168+
instead.
169+
163170
TwigBridge
164171
----------
165172

UPGRADE-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ Translation
580580
-----------
581581

582582
* Removed the backup feature from the file dumper classes.
583+
584+
* Removed `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations`,
585+
use `Symfony\Component\Translation\Writer\TranslationWriter::write` instead.
583586

584587
TwigBundle
585588
----------

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Symfony\Component\Console\Input\InputOption;
2222
use Symfony\Component\Translation\Extractor\ExtractorInterface;
2323
use Symfony\Component\Translation\MessageCatalogue;
24-
use Symfony\Component\Translation\Writer\TranslationWriter;
24+
use Symfony\Component\Translation\Writer\TranslationWriterInterface;
2525

2626
/**
2727
* A command that parses templates to extract translation messages and adds them
@@ -39,14 +39,14 @@ class TranslationUpdateCommand extends ContainerAwareCommand
3939
private $defaultLocale;
4040

4141
/**
42-
* @param TranslationWriter $writer
43-
* @param TranslationLoader $loader
44-
* @param ExtractorInterface $extractor
45-
* @param string $defaultLocale
42+
* @param TranslationWriterInterface $writer
43+
* @param TranslationLoader $loader
44+
* @param ExtractorInterface $extractor
45+
* @param string $defaultLocale
4646
*/
4747
public function __construct($writer = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null, $defaultLocale = null)
4848
{
49-
if (!$writer instanceof TranslationWriter) {
49+
if (!$writer instanceof TranslationWriterInterface) {
5050
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
5151

5252
parent::__construct($writer);
@@ -276,7 +276,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
276276
$bundleTransPath = end($transPaths).'translations';
277277
}
278278

279-
$this->writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->defaultLocale));
279+
$this->writer->write($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->defaultLocale));
280280

281281
if (true === $input->getOption('dump-messages')) {
282282
$resultMessage .= ' and translation files were updated';

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ CHANGELOG
88
* Added `TranslationExtractorPass`
99
* Added `TranslatorPass`
1010
* Added <notes> section to the Xliff 2.0 dumper.
11+
* Added `TranslationWriterInterface`
12+
* Deprecated `TranslationWriter::writeTranslations` in favor of `TranslationWriter::write`
1113

1214
3.2.0
1315
-----

src/Symfony/Component/Translation/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();

src/Symfony/Component/Translation/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 <michelsalib@hotmail.com>
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
}
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 <fabien@symfony.com>
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 <michelsalib@hotmail.com>
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)