[Translator] deprecate getMessages in favor of getCatalogue.
This commit is contained in:
parent
197396089f
commit
2869a32cf1
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
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
2.8.0
|
||||||
|
-----
|
||||||
|
* deprecated Translator::getMessages(), rely on the TranslatorBagInterface::getCatalogue() method instead.
|
||||||
|
|
||||||
2.7.0
|
2.7.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -497,9 +497,10 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @group legacy
|
||||||
* @dataProvider dataProviderGetMessages
|
* @dataProvider dataProviderGetMessages
|
||||||
*/
|
*/
|
||||||
public function testGetMessages($resources, $locale, $expected)
|
public function testLegacyGetMessages($resources, $locale, $expected)
|
||||||
{
|
{
|
||||||
$locales = array_keys($resources);
|
$locales = array_keys($resources);
|
||||||
$_locale = !is_null($locale) ? $locale : reset($locales);
|
$_locale = !is_null($locale) ? $locale : reset($locales);
|
||||||
|
@ -292,6 +292,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
*/
|
*/
|
||||||
public function getMessages($locale = null)
|
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 = array();
|
||||||
$catalogues[] = $catalogue = $this->getCatalogue($locale);
|
$catalogues[] = $catalogue = $this->getCatalogue($locale);
|
||||||
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
||||||
|
Reference in New Issue
Block a user