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

Skip to content

Commit f36430d

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

File tree

3 files changed

+6
-31
lines changed

3 files changed

+6
-31
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->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: 5 additions & 23 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])) {

0 commit comments

Comments
 (0)
0