Skip to content

Commit

Permalink
[Translator] deprecate getMessages in favor of getCatalogue.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed May 6, 2015
1 parent 1973960 commit 2869a32
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
24 changes: 24 additions & 0 deletions UPGRADE-2.8.md
@@ -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);
}
```
4 changes: 4 additions & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
@@ -1,6 +1,10 @@
CHANGELOG
=========

2.8.0
-----
* deprecated Translator::getMessages(), rely on the TranslatorBagInterface::getCatalogue() method instead.

2.7.0
-----

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Translation/Tests/TranslatorTest.php
Expand Up @@ -497,9 +497,10 @@ public function testTransChoiceFallbackWithNoTranslation()
}

/**
* @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);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Translation/Translator.php
Expand Up @@ -292,6 +292,8 @@ protected function getLoaders()
*/
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()) {
Expand Down

0 comments on commit 2869a32

Please sign in to comment.