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

Skip to content

Commit 03beebb

Browse files
committed
[Translator] deprecate getMessages in favor of getCatalogue.
1 parent 1973960 commit 03beebb

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

UPGRADE-2.8.md

Lines changed: 24 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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() instead.
7+
48
2.7.0
59
-----
610

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ public function testTransChoiceFallbackWithNoTranslation()
499499
/**
500500
* @dataProvider dataProviderGetMessages
501501
*/
502-
public function testGetMessages($resources, $locale, $expected)
502+
public function testLegacyGetMessages($resources, $locale, $expected)
503503
{
504+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
505+
504506
$locales = array_keys($resources);
505507
$_locale = !is_null($locale) ? $locale : reset($locales);
506508
$locales = array_slice($locales, 0, array_search($_locale, $locales));

src/Symfony/Component/Translation/Translator.php

Lines changed: 2 additions & 0 deletions
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 instead', E_USER_DEPRECATED);
296+
295297
$catalogues = array();
296298
$catalogues[] = $catalogue = $this->getCatalogue($locale);
297299
while ($catalogue = $catalogue->getFallbackCatalogue()) {

0 commit comments

Comments
 (0)