minor #14370 [2.6][Translation] remove duplicate code for loading catalogue. (aitboudad)
This PR was merged into the 2.6 branch.
Discussion
----------
[2.6][Translation] remove duplicate code for loading catalogue.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Fixed tickets | ~
| Tests pass? | yes
| License | MIT
Commits
-------
973ee2e
[2.6][Translation] remove duplicate code for loading catalogue.
This commit is contained in:
commit
7b2873f983
@ -109,10 +109,6 @@ class LoggingTranslator implements TranslatorInterface, TranslatorBagInterface
|
||||
*/
|
||||
private function log($id, $domain, $locale)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
}
|
||||
|
||||
if (null === $domain) {
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
@ -203,21 +203,11 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
*/
|
||||
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
} else {
|
||||
$this->assertValidLocale($locale);
|
||||
}
|
||||
|
||||
if (null === $domain) {
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
||||
if (!isset($this->catalogues[$locale])) {
|
||||
$this->loadCatalogue($locale);
|
||||
}
|
||||
|
||||
return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
|
||||
return strtr($this->getCatalogue($locale)->get((string) $id, $domain), $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,23 +217,13 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
*/
|
||||
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
} else {
|
||||
$this->assertValidLocale($locale);
|
||||
}
|
||||
|
||||
if (null === $domain) {
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
||||
if (!isset($this->catalogues[$locale])) {
|
||||
$this->loadCatalogue($locale);
|
||||
}
|
||||
|
||||
$id = (string) $id;
|
||||
|
||||
$catalogue = $this->catalogues[$locale];
|
||||
$catalogue = $this->getCatalogue($locale);
|
||||
$locale = $catalogue->getLocale();
|
||||
while (!$catalogue->defines($id, $domain)) {
|
||||
if ($cat = $catalogue->getFallbackCatalogue()) {
|
||||
$catalogue = $cat;
|
||||
@ -263,6 +243,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
} else {
|
||||
$this->assertValidLocale($locale);
|
||||
}
|
||||
|
||||
if (!isset($this->catalogues[$locale])) {
|
||||
@ -291,16 +273,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
*/
|
||||
public function getMessages($locale = null)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
}
|
||||
|
||||
if (!isset($this->catalogues[$locale])) {
|
||||
$this->loadCatalogue($locale);
|
||||
}
|
||||
|
||||
$catalogues = array();
|
||||
$catalogues[] = $catalogue = $this->catalogues[$locale];
|
||||
$catalogues[] = $catalogue = $this->getCatalogue($locale);
|
||||
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
||||
$catalogues[] = $catalogue;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Translation;
|
||||
|
||||
/**
|
||||
* TranslatorBagInterface
|
||||
* TranslatorBagInterface.
|
||||
*
|
||||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
||||
*/
|
||||
@ -23,6 +23,8 @@ interface TranslatorBagInterface
|
||||
*
|
||||
* @param string|null $locale The locale or null to use the default
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*
|
||||
* @return MessageCatalogueInterface
|
||||
*/
|
||||
public function getCatalogue($locale = null);
|
||||
|
Reference in New Issue
Block a user