Skip to content

Commit 6cb4f03

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

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
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/Bundle/FrameworkBundle/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
7878
public function warmUp($cacheDir)
7979
{
8080
foreach ($this->resourceLocales as $locale) {
81-
$this->loadCatalogue($locale);
81+
$this->getCatalogue($locale);
8282
}
8383
}
8484

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.8.0
5+
-----
6+
* deprecated Translator::getMessages() and Translator::loadCatalogue(),
7+
rely on the TranslatorBagInterface::getCatalogue() instead.
8+
49
2.7.0
510
-----
611

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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ public function getCatalogue($locale = null)
267267
}
268268

269269
if (!isset($this->catalogues[$locale])) {
270-
$this->loadCatalogue($locale);
270+
if (null === $this->cacheDir) {
271+
$this->initializeCatalogue($locale);
272+
} else {
273+
$this->initializeCacheCatalogue($locale);
274+
}
271275
}
272276

273277
return $this->catalogues[$locale];
@@ -292,6 +296,8 @@ protected function getLoaders()
292296
*/
293297
public function getMessages($locale = null)
294298
{
299+
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);
300+
295301
$catalogues = array();
296302
$catalogues[] = $catalogue = $this->getCatalogue($locale);
297303
while ($catalogue = $catalogue->getFallbackCatalogue()) {
@@ -311,11 +317,9 @@ public function getMessages($locale = null)
311317
*/
312318
protected function loadCatalogue($locale)
313319
{
314-
if (null === $this->cacheDir) {
315-
$this->initializeCatalogue($locale);
316-
} else {
317-
$this->initializeCacheCatalogue($locale);
318-
}
320+
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);
321+
322+
return $this->getCatalogue($locale);
319323
}
320324

321325
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy