8000 [2.6][Translation] remove duplicate code for loading catalogue. by aitboudad · Pull Request #14370 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
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
4 changes: 0 additions & 4 deletions src/Symfony/Component/Translation/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 src/Symfony/Component/Translation/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 src/Symfony/Component/Translation/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