Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55b3525

Browse files
committed
feature #14546 [Translator] deprecate getMessages in favor of getCatalogue. (aitboudad)
This PR was merged into the 2.8 branch. Discussion ---------- [Translator] deprecate getMessages in favor of getCatalogue. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | #14529 | Tests pass? | yes | License | MIT Commits ------- 2869a32 [Translator] deprecate getMessages in favor of getCatalogue.
2 parents 1973960 + 2869a32 commit 55b3525

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

UPGRADE-2.8.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
UPGRADE FROM 2.7 to 2.8
2+
=======================
3+
4+
Translator
5+
----------
6+
* The `getMessages()` method of the `Symfony\Component\Translation\Translator` was deprecated and will be removed in
7+
Symfony 3.0. You should use the `getCatalogue()` method of the `Symfony\Component\Translation\TranslatorBagInterface`.
8+
9+
Before:
10+
11+
```php
12+
$messages = $translator->getMessages();
13+
```
14+
15+
After:
16+
17+
```php
18+
$catalogue = $translator->getCatalogue($locale);
19+
$messages = $catalogue->all();
20+
21+
while ($catalogue = $catalogue->getFallbackCatalogue()) {
22+
$messages = array_replace_recursive($catalogue->all(), $messages);
23+
}
24+
```

src/Symfony/Component/Translation/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
2.8.0
5+
-----
6+
* deprecated Translator::getMessages(), rely on the TranslatorBagInterface::getCatalogue() method instead.
7+
48
2.7.0
59
-----
610

src/Symfony/Component/Translation/Tests/TranslatorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,10 @@ public function testTransChoiceFallbackWithNoTranslation()
497497
}
498498

499499
/**
500+
* @group legacy
500501
* @dataProvider dataProviderGetMessages
501502
*/
502-
public function testGetMessages($resources, $locale, $expected)
503+
public function testLegacyGetMessages($resources, $locale, $expected)
503504
{
504505
$locales = array_keys($resources);
505506
$_locale = !is_null($locale) ? $locale : reset($locales);

src/Symfony/Component/Translation/Translator.php

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ protected function getLoaders()
292292
*/
293293
public function getMessages($locale = null)
294294
{
295+
trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Rely on the TranslatorBagInterface::getCatalogue() method instead', E_USER_DEPRECATED);
296+
295297
$catalogues = array();
296298
$catalogues[] = $catalogue = $this->getCatalogue($locale);
297299
while ($catalogue = $catalogue->getFallbackCatalogue()) {

0 commit comments

Comments
 (0)