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)
|
private function log($id, $domain, $locale)
|
||||||
{
|
{
|
||||||
if (null === $locale) {
|
|
||||||
$locale = $this->getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $domain) {
|
if (null === $domain) {
|
||||||
$domain = 'messages';
|
$domain = 'messages';
|
||||||
}
|
}
|
||||||
|
@ -203,21 +203,11 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
*/
|
*/
|
||||||
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
|
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
|
||||||
{
|
{
|
||||||
if (null === $locale) {
|
|
||||||
$locale = $this->getLocale();
|
|
||||||
} else {
|
|
||||||
$this->assertValidLocale($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $domain) {
|
if (null === $domain) {
|
||||||
$domain = 'messages';
|
$domain = 'messages';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->catalogues[$locale])) {
|
return strtr($this->getCatalogue($locale)->get((string) $id, $domain), $parameters);
|
||||||
$this->loadCatalogue($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtr($this->catalogues[$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)
|
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) {
|
if (null === $domain) {
|
||||||
$domain = 'messages';
|
$domain = 'messages';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->catalogues[$locale])) {
|
|
||||||
$this->loadCatalogue($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = (string) $id;
|
$id = (string) $id;
|
||||||
|
$catalogue = $this->getCatalogue($locale);
|
||||||
$catalogue = $this->catalogues[$locale];
|
$locale = $catalogue->getLocale();
|
||||||
while (!$catalogue->defines($id, $domain)) {
|
while (!$catalogue->defines($id, $domain)) {
|
||||||
if ($cat = $catalogue->getFallbackCatalogue()) {
|
if ($cat = $catalogue->getFallbackCatalogue()) {
|
||||||
$catalogue = $cat;
|
$catalogue = $cat;
|
||||||
@ -263,6 +243,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
{
|
{
|
||||||
if (null === $locale) {
|
if (null === $locale) {
|
||||||
$locale = $this->getLocale();
|
$locale = $this->getLocale();
|
||||||
|
} else {
|
||||||
|
$this->assertValidLocale($locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->catalogues[$locale])) {
|
if (!isset($this->catalogues[$locale])) {
|
||||||
@ -291,16 +273,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
*/
|
*/
|
||||||
public function getMessages($locale = null)
|
public function getMessages($locale = null)
|
||||||
{
|
{
|
||||||
if (null === $locale) {
|
|
||||||
$locale = $this->getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->catalogues[$locale])) {
|
|
||||||
$this->loadCatalogue($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
$catalogues = array();
|
$catalogues = array();
|
||||||
$catalogues[] = $catalogue = $this->catalogues[$locale];
|
$catalogues[] = $catalogue = $this->getCatalogue($locale);
|
||||||
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
while ($catalogue = $catalogue->getFallbackCatalogue()) {
|
||||||
$catalogues[] = $catalogue;
|
$catalogues[] = $catalogue;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Translation;
|
namespace Symfony\Component\Translation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TranslatorBagInterface
|
* TranslatorBagInterface.
|
||||||
*
|
*
|
||||||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
* @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
|
* @param string|null $locale The locale or null to use the default
|
||||||
*
|
*
|
||||||
|
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||||
|
*
|
||||||
* @return MessageCatalogueInterface
|
* @return MessageCatalogueInterface
|
||||||
*/
|
*/
|
||||||
public function getCatalogue($locale = null);
|
public function getCatalogue($locale = null);
|
||||||
|
Reference in New Issue
Block a user