Skip to content

Commit

Permalink
[2.6][Translation] remove duplicate code for loading catalogue.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Apr 16, 2015
1 parent 8c7883d commit 34e480d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
4 changes: 0 additions & 4 deletions LoggingTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ public function __call($method, $args)
*/
private function log($id, $domain, $locale)
{
if (null === $locale) {
$locale = $this->getLocale();
}

if (null === $domain) {
$domain = 'messages';
}
Expand Down
38 changes: 6 additions & 32 deletions Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,11 @@ public function getFallbackLocales()
*/
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);
}

/**
Expand All @@ -227,23 +217,13 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
*/
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;
Expand All @@ -263,6 +243,8 @@ public function getCatalogue($locale = null)
{
if (null === $locale) {
$locale = $this->getLocale();
} else {
$this->assertValidLocale($locale);
}

if (!isset($this->catalogues[$locale])) {
Expand Down Expand Up @@ -291,16 +273,8 @@ protected function getLoaders()
*/
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;
}
Expand Down
4 changes: 3 additions & 1 deletion TranslatorBagInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Translation;

/**
* TranslatorBagInterface
* TranslatorBagInterface.
*
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
*/
Expand All @@ -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);
Expand Down

0 comments on commit 34e480d

Please sign in to comment.