[2.6][Translation] remove duplicate code for loading catalogue.
This commit is contained in:
parent
eb2ff793e8
commit
973ee2e1e4
@ -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