Skip to content

Commit 3af9334

Browse files
author
jockri
committed
Merge pull request #37 from Kunstmaan/fix-translator-loader
fix translator loader bug
2 parents 216f2ac + 2045084 commit 3af9334

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

Service/Translator/Loader.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,22 @@
1212
class Loader implements LoaderInterface
1313
{
1414
private $translationRepository;
15-
private $translations;
15+
private $catalogues = array();
1616

1717
/**
1818
* @{@inheritdoc}
1919
*/
2020
public function load($resource, $locale, $domain = 'messages')
2121
{
22-
$catalogue = new MessageCatalogue($locale);
23-
24-
if (!$this->translations)
25-
{
26-
$this->translations = array();
27-
$translations = $this->translationRepository->findBy(array('domain' => $domain));
28-
29-
if ($translations)
30-
{
31-
foreach ($translations as $trans)
32-
{
33-
if (!key_exists($trans->getLocale(), $this->translations))
34-
{
35-
$this->translations[$trans->getLocale()] = array();
36-
}
37-
$this->translations[$trans->getLocale()][] = $trans;
38-
}
22+
if (!isset($this->catalogues[$locale])) {
23+
$catalogue = new MessageCatalogue($locale);
24+
$translations = $this->translationRepository->findBy(array('locale' => $locale));
25+
foreach ($translations as $translation) {
26+
$catalogue->set($translation->getKeyword(), $translation->getText(), $translation->getDomain());
3927
}
40-
}
41-
$translations = $this->translations[$locale];
42-
43-
foreach ($translations as $translation) {
44-
$catalogue->set($translation->getKeyword(), $translation->getText(), $domain);
28+
$this->catalogues[$locale] = $catalogue;
29+
} else {
30+
$catalogue = $this->catalogues[$locale];
4531
}
4632

4733
return $catalogue;

0 commit comments

Comments
 (0)