8000 [Translation] remove duplicate code for loading catalogue. · symfony/symfony@d742a24 · GitHub
[go: up one dir, main page]

Skip to content

Commit d742a24

Browse files
committed
[Translation] remove duplicate code for loading catalogue.
1 parent 222701f commit d742a24

File tree

4 files changed

+10
-41
lines changed

4 files changed

+10
-41
lines changed

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,13 @@ public function getCollectedMessages()
116116
*/
117117
private function collectMessage($locale, $domain, $id, $translation)
118118
{
119-
if (null === $locale) {
120-
$locale = $this->getLocale();
121-
}
122-
123119
if (null === $domain) {
124120
$domain = 'messages';
125121
}
126122

127123
$id = (string) $id;
128124
$catalogue = $this->translator->getCatalogue($locale);
125+
$locale = $catalogue->getLocale();
129126
if ($catalogue 10000 ->defines($id, $domain)) {
130127
$state = self::MESSAGE_DEFINED;
131128
} elseif ($catalogue->has($id, $domain)) {

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ public function __call($method, $args)
109109
*/
110110
private function log($id, $domain, $locale)
111111
{
112-
if (null === $locale) {
113-
$locale = $this->getLocale();
114-
}
115-
116112
if (null === $domain) {
117113
$domain = 'messages';
118114
}

src/Symfony/Component/Translation/Translator.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,11 @@ public function getFallbackLocales()
222222
*/
223223
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
224224
{
225-
if (null === $locale) {
226-
$locale = $this->getLocale();
227-
} else {
228-
$this->assertValidLocale($locale);
229-
}
230-
231225
if (null === $domain) {
232226
$domain = 'messages';
233227
}
234228

235-
if (!isset($this->catalogues[$locale])) {
236-
$this->loadCatalogue($locale);
237-
}
238-
239-
return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
229+
return strtr($this->getCatalogue($locale)->get((string) $id, $domain), $parameters);
240230
}
241231

242232
/**
@@ -246,23 +236,13 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
246236
*/
247237
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
248238
{
249-
if (null === $locale) {
250-
$locale = $this->getLocale();
251-
} else {
252-
$this->assertValidLocale($locale);
253-
}
254-
255239
if (null === $domain) {
256240
$domain = 'messages';
257241
}
258242

259-
if (!isset($this->catalogues[$locale])) {
260-
$this->loadCatalogue($locale);
261-
}
262-
263243
$id = (string) $id;
264-
265-
$catalogue = $this->catalogues[$locale];
244+
$catalogue = $this->getCatalogue($locale);
245+
$locale = $catalogue->getLocale();
266246
while (!$catalogue->defines($id, $domain)) {
267247
if ($cat = $catalogue->getFallbackCatalogue()) {
268248
$catalogue = $cat;
@@ -282,6 +262,8 @@ public function getCatalogue($locale = null)
282262
{
283263
if (null === $locale) {
284264
$locale = $this->getLocale();
265+
} else {
266+
$this->assertValidLocale($locale);
285267
}
286268

287269
if (!isset($this->catalogues[$locale])) {
@@ -310,16 +292,8 @@ protected function getLoaders()
310292
*/
311293
public function getMessages($locale = null)
312294
{
313-
if (null === $locale) {
314-
$locale = $this->getLocale();
315-
}
316-
317-
if (!isset($this->catalogues[$locale])) {
318-
$this->loadCatalogue($locale);
319-
}
320-
321295
$catalogues = array();
322-
$catalogues[] = $catalogue = $this->catalogues[$locale];
296+
$catalogues[] = $catalogue = $this->getCatalogue($locale);
323297
while ($catalogue = $catalogue->getFallbackCatalogue()) {
324298
$catalogues[] = $catalogue;
325299
}

src/Symfony/Component/Translation/TranslatorBagInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Translation;
1313

1414
/**
15-
* TranslatorBagInterface
15+
* TranslatorBagInterface.
1616
*
1717
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
1818
*/
@@ -23,6 +23,8 @@ interface TranslatorBagInterface
2323
*
2424
* @param string|null $locale The locale or null to use the default
2525
*
26+
* @throws \InvalidArgumentException If the locale contains invalid characters
27+
*
2628
* @return MessageCatalogueInterface
2729
*/
2830
public function getCatalogue($locale = null);

0 commit comments

Comments
 (0)
0