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.
This commit is contained in:
commit
55b352538b
24
UPGRADE-2.8.md
Normal file
24
UPGRADE-2.8.md
Normal file
@ -0,0 +1,24 @@
|
||||
UPGRADE FROM 2.7 to 2.8
|
||||
=======================
|
||||
|
||||
Translator
|
||||
----------
|
||||
* The `getMessages()` method of the `Symfony\Component\Translation\Translator` was deprecated and will be removed in
|
||||
Symfony 3.0. You should use the `getCatalogue()` method of the `Symfony\Component\Translation\TranslatorBagInterface`.
|
||||
|
||||
Before:
|
||||
|
||||
```php
|
||||
$messages = $translator->getMessages();
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```php
|
||||
$catalogue = $translator->getCatalogue($locale);
|
||||
$messages = $catalogue->all();
|
||||
|
||||
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
||||
$messages = array_replace_recursive($catalogue->all(), $messages);
|
||||
}
|
||||
```
|
@ -1,6 +1,10 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.8.0
|
||||
-----
|
||||
* deprecated Translator::getMessages(), rely on the TranslatorBagInterface::getCatalogue() method instead.
|
||||
|
||||
2.7.0
|
||||
-----
|
||||
|
||||
|
@ -497,9 +497,10 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider dataProviderGetMessages
|
||||
*/
|
||||
public function testGetMessages($resources, $locale, $expected)
|
||||
public function testLegacyGetMessages($resources, $locale, $expected)
|
||||
{
|
||||
$locales = array_keys($resources);
|
||||
$_locale = !is_null($locale) ? $locale : reset($locales);
|
||||
|
@ -292,6 +292,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
*/
|
||||
public function getMessages($locale = null)
|
||||
{
|
||||
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);
|
||||
|
||||
$catalogues = array();
|
||||
$catalogues[] = $catalogue = $this->getCatalogue($locale);
|
||||
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
||||
|
Reference in New Issue
Block a user