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

Skip to content

Commit bf86171

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

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,14 @@ public function getCollectedMessages()< 8000 /div>
116116
*/
117117
private function collectMessage($locale, $domain, $id, $translation)
118118
{
119-
if (null === $locale) {
120-
$locale = $this->getLocale();
121-
}
119+
$catalogue = $this->translator->getCatalogue($locale);
120+
$locale = $catalogue->getLocale();
122121

123122
if (null === $domain) {
124123
$domain = 'messages';
125124
}
126125

127126
$id = (string) $id;
128-
$catalogue = $this->translator->getCatalogue($locale);
129127
if ($catalogue->defines($id, $domain)) {
130128
$state = self::MESSAGE_DEFINED;
131129
} elseif ($catalogue->has($id, $domain)) {

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,13 @@ public function __call($method, $args)
109109
*/
110110
private function log($id, $domain, $locale)
111111
{
112-
if (null === $locale) {
113-
$locale = $this->getLocale();
114-
}
112+
$catalogue = $this->translator->getCatalogue($locale);
115113

116114
if (null === $domain) {
117115
$domain = 'messages';
118116
}
119117

120118
$id = (string) $id;
121-
$catalogue = $this->translator->getCatalogue($locale);
122119
if ($catalogue->defines($id, $domain)) {
123120
return;
124121
}

src/Symfony/Component/Translation/Translator.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,13 @@ 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-
}
225+
$catalogue = $this->getCatalogue($locale);
230226

231227
if (null === $domain) {
232228
$domain = 'messages';
233229
}
234230

235-
if (!isset($this->catalogues[$locale])) {
236-
$this->loadCatalogue($locale);
237-
}
238-
239-
return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
231+
return strtr($catalogue->get((string) $id, $domain), $parameters);
240232
}
241233

242234
/**
@@ -246,23 +238,14 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
246238
*/
247239
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
248240
{
249-
if (null === $locale) {
250-
$locale = $this->getLocale();
251-
} else {
252-
$this->assertValidLocale($locale);
253-
}
241+
$catalogue = $this->getCatalogue($locale);
254242

255243
if (null === $domain) {
256244
$domain = 'messages';
257245
}
258246

259-
if (!isset($this->catalogues[$locale])) {
260-
$this->loadCatalogue($locale);
261-
}
262-
263247
$id = (string) $id;
264-
265-
$catalogue = $this->catalogues[$locale];
248+
$locale = $catalogue->getLocale();
266249
while (!$catalogue->defines($id, $domain)) {
267250
if ($cat = $catalogue->getFallbackCatalogue()) {
268251
$catalogue = $cat;
@@ -282,6 +265,8 @@ public function getCatalogue($locale = null)
282265
{
283266
if (null === $locale) {
284267
$locale = $this->getLocale();
268+
} else {
269+
$this->assertValidLocale($locale);
285270
}
286271

287272
if (!isset($this->catalogues[$locale])) {

0 commit comments

Comments
 (0)
0