Skip to content

[Translator] deprecate getMessages in favor of getCatalogue. #14546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions UPGRADE-2.8.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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