Skip to content

Commit 173b747

Browse files
committed
feature symfony#23667 [Translation] Create an TranslationReaderInterface and move TranslationLoader to TranslationComponent (Nyholm)
This PR was merged into the 3.4 branch. Discussion ---------- [Translation] Create an TranslationReaderInterface and move TranslationLoader to TranslationComponent | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Create an interface for TranslationLoader. I put this in the Translation component even though the TranslationLoader implementation is in the FrameworkBundle. (Here is a PR moving the TranslationLoader to the Translation component: symfony#23666) We need this in PHP-translation. We currently have to rewrite things in strange mannar like: https://github.com/php-translation/symfony-storage/blob/0.2.2/src/FileStorage.php#L62-L64 Commits ------- 5bc50da Create an interface for TranslationReader and moved TranslationLoader to Translation component
2 parents d00ac8a + 5bc50da commit 173b747

File tree

17 files changed

+231
-76
lines changed

17 files changed

+231
-76
lines changed

UPGRADE-3.4.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ FrameworkBundle
114114
class has been deprecated and will be removed in 4.0. Use the
115115
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
116116

117+
* The `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`
118+
class has been deprecated and will be removed in 4.0. Use the
119+
`Symfony\Component\Translation\Reader\TranslationReader` class instead.
120+
121+
* The `translation.loader` service has been deprecated and will be removed in 4.0. Use the `translation.reader` service instead.
122+
117123
HttpKernel
118124
----------
119125

UPGRADE-4.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,13 @@ FrameworkBundle
414414
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass`
415415
class has been removed. Use the
416416
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
417+
418+
* The `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`
419+
class has been deprecated and will be removed in 4.0. Use the
420+
`Symfony\Component\Translation\Reader\TranslationReader` class instead.
417421

422+
* The `translation.loader` service has been deprecated and will be removed in 4.0. Use the `translation.reader` service instead.
423+
418424
HttpFoundation
419425
--------------
420426

@@ -581,6 +587,8 @@ Translation
581587

582588
* Removed the backup feature from the file dumper classes.
583589

590+
* The default value of the `$readerServiceId` argument of `TranslatorPass::__construct()` has been changed to `"translation.reader"`.
591+
584592
* Removed `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations`,
585593
use `Symfony\Component\Translation\Writer\TranslationWriter::write` instead.
586594

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ CHANGELOG
2323
name as value, using it makes the command lazy
2424
* Added `cache:pool:prune` command to allow manual stale cache item pruning of supported PSR-6 and PSR-16 cache pool
2525
implementations
26+
* Deprecated `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`, use
27+
`Symfony\Component\Translation\Reader\TranslationReader` instead
28+
* Deprecated `translation.loader` service, use `translation.reader` instead
2629

2730
3.3.0
2831
-----

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader;
1514
use Symfony\Component\Console\Style\SymfonyStyle;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Input\InputArgument;
@@ -21,6 +20,7 @@
2120
use Symfony\Component\Translation\Catalogue\MergeOperation;
2221
use Symfony\Component\Translation\Extractor\ExtractorInterface;
2322
use Symfony\Component\Translation\MessageCatalogue;
23+
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
2424
use Symfony\Component\Translation\Translator;
2525
use Symfony\Component\Translation\DataCollectorTranslator;
2626
use Symfony\Component\Translation\LoggingTranslator;
@@ -43,15 +43,15 @@ class TranslationDebugCommand extends ContainerAwareCommand
4343
protected static $defaultName = 'debug:translation';
4444

4545
private $translator;
46-
private $loader;
46+
private $reader;
4747
private $extractor;
4848

4949
/**
50-
* @param TranslatorInterface $translator
51-
* @param TranslationLoader $loader
52-
* @param ExtractorInterface $extractor
50+
* @param TranslatorInterface $translator
51+
* @param TranslationReaderInterface $reader
52+
* @param ExtractorInterface $extractor
5353
*/
54-
public function __construct($translator = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null)
54+
public function __construct($translator = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null)
5555
{
5656
if (!$translator instanceof TranslatorInterface) {
5757
@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);
@@ -64,7 +64,7 @@ public function __construct($translator = null, TranslationLoader $loader = null
6464
parent::__construct();
6565

6666
$this->translator = $translator;
67-
$this->loader = $loader;
67+
$this->reader = $reader;
6868
$this->extractor = $extractor;
6969
}
7070

@@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
142142
// BC to be removed in 4.0
143143
if (null === $this->translator) {
144144
$this->translator = $this->getContainer()->get('translator');
145-
$this->loader = $this->getContainer()->get('translation.loader');
145+
$this->reader = $this->getContainer()->get('translation.reader');
146146
$this->extractor = $this->getContainer()->get('translation.extractor');
147147
}
148148

@@ -331,7 +331,7 @@ private function loadCurrentMessages($locale, $transPaths)
331331
foreach ($transPaths as $path) {
332332
$path = $path.'translations';
333333
if (is_dir($path)) {
334-
$this->loader->loadMessages($path, $currentCatalogue);
334+
$this->reader->read($path, $currentCatalogue);
335335
}
336336
}
337337

@@ -357,7 +357,7 @@ private function loadFallbackCatalogues($locale, $transPaths)
357357
foreach ($transPaths as $path) {
358358
$path = $path.'translations';
359359
if (is_dir($path)) {
360-
$this->loader->loadMessages($path, $fallbackCatalogue);
360+
$this->reader->read($path, $fallbackCatalogue);
361361
}
362362
}
363363
$fallbackCatalogues[] = $fallbackCatalogue;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader;
1514
use Symfony\Component\Console\Style\SymfonyStyle;
1615
use Symfony\Component\Translation\Catalogue\TargetOperation;
1716
use Symfony\Component\Translation\Catalogue\MergeOperation;
@@ -21,6 +20,7 @@
2120
use Symfony\Component\Console\Input\InputOption;
2221
use Symfony\Component\Translation\Extractor\ExtractorInterface;
2322
use Symfony\Component\Translation\MessageCatalogue;
23+
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
2424
use Symfony\Component\Translation\Writer\TranslationWriterInterface;
2525

2626
/**
@@ -36,17 +36,17 @@ class TranslationUpdateCommand extends ContainerAwareCommand
3636
protected static $defaultName = 'translation:update';
3737

3838
private $writer;
39-
private $loader;
39+
private $reader;
4040
private $extractor;
4141
private $defaultLocale;
4242

4343
/**
4444
* @param TranslationWriterInterface $writer
45-
* @param TranslationLoader $loader
45+
* @param TranslationReaderInterface $reader
4646
* @param ExtractorInterface $extractor
4747
* @param string $defaultLocale
4848
*/
49-
public function __construct($writer = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null, $defaultLocale = null)
49+
public function __construct($writer = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null, $defaultLocale = null)
5050
{
5151
if (!$writer instanceof TranslationWriterInterface) {
5252
@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);
@@ -59,7 +59,7 @@ public function __construct($writer = null, TranslationLoader $loader = null, Ex
5959
parent::__construct();
6060

6161
$this->writer = $writer;
62-
$this->loader = $loader;
62+
$this->reader = $reader;
6363
$this->extractor = $extractor;
6464
$this->defaultLocale = $defaultLocale;
6565
}
@@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
127127
// BC to be removed in 4.0
128128
if (null === $this->writer) {
129129
$this->writer = $this->getContainer()->get('translation.writer');
130-
$this->loader = $this->getContainer()->get('translation.loader');
130+
$this->reader = $this->getContainer()->get('translation.reader');
131131
$this->extractor = $this->getContainer()->get('translation.extractor');
132132
$this->defaultLocale = $this->getContainer()->getParameter('kernel.default_locale');
133133
}
@@ -201,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
201201
foreach ($transPaths as $path) {
202202
$path .= 'translations';
203203
if (is_dir($path)) {
204-
$this->loader->loadMessages($path, $currentCatalogue);
204+
$this->reader->read($path, $currentCatalogue);
205205
}
206206
}
207207

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ public function build(ContainerBuilder $container)
9696
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
9797
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
9898
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
99-
$this->addCompilerPassIfExists($container, TranslatorPass::class);
99+
if (class_exists(TranslatorPass::class)) {
100+
// Arguments to be removed in 4.0, relying on the default values
101+
$container->addCompilerPass(new TranslatorPass('translator.default', 'translation.loader'));
102+
}
100103
$container->addCompilerPass(new LoggingTranslatorPass());
101104
$container->addCompilerPass(new AddCacheWarmerPass());
102105
$container->addCompilerPass(new AddCacheClearerPass());

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@
121121
<tag name="translation.extractor" alias="php" />
122122
</service>
123123

124-
<service id="translation.loader" class="Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader" public="true" />
124+
<service id="translation.loader" class="Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader" public="true">
125+
<deprecated>The "%service_id%" service is deprecated since Symfony 3.4 and will be removed in 4.0. Use "translation.reader" instead.</deprecated>
126+
</service>
127+
<service id="translation.reader" class="Symfony\Component\Translation\Reader\TranslationReader" public="true" />
125128

126129
<service id="translation.extractor" class="Symfony\Component\Translation\Extractor\ChainExtractor" public="true" />
127130

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
130130
})
131131
);
132132

133-
$loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader')->getMock();
133+
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
134134
$loader
135135
->expects($this->any())
136-
->method('loadMessages')
136+
->method('read')
137137
->will(
138138
$this->returnCallback(function ($path, $catalogue) use ($loadedMessages) {
139139
$catalogue->add($loadedMessages);
@@ -197,7 +197,7 @@ public function testLegacyDebugCommand()
197197
->method('get')
198198
->will($this->returnValueMap(array(
199199
array('translation.extractor', 1, $extractor),
200-
array('translation.loader', 1, $loader),
200+
array('translation.reader', 1, $loader),
201201
array('translator', 1, $translator),
202202
array('kernel', 1, $kernel),
203203
)));

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
101101
})
102102
);
103103

104-
$loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader')->getMock();
104+
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
105105
$loader
106106
->expects($this->any())
107-
->method('loadMessages')
107+
->method('read')
108108
->will(
109109
$this->returnCallback(function ($path, $catalogue) use ($loadedMessages) {
110110
$catalogue->add($loadedMessages);
@@ -177,7 +177,7 @@ public function testLegacyUpdateCommand()
177177
->method('get')
178178
->will($this->returnValueMap(array(
179179
array('translation.extractor', 1, $extractor),
180-
array('translation.loader', 1, $loader),
180+
array('translation.reader', 1, $loader),
181181
array('translation.writer', 1, $writer),
182182
array('translator', 1, $translator),
183183
array('kernel', 1, $kernel),

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
10001000
$container->getCompilerPassConfig()->setOptimizationPasses(array());
10011001
$container->getCompilerPassConfig()->setRemovingPasses(array());
10021002
}
1003-
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass(), new AddConstraintValidatorsPass(), new TranslatorPass()));
1003+
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass(), new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
10041004
$container->compile();
10051005

10061006
return self::$containerCache[$cacheKey] = $container;

0 commit comments

Comments
 (0)