|
12 | 12 | class Loader implements LoaderInterface |
13 | 13 | { |
14 | 14 | private $translationRepository; |
15 | | - private $translations; |
| 15 | + private $catalogues = array(); |
16 | 16 |
|
17 | 17 | /** |
18 | 18 | * @{@inheritdoc} |
19 | 19 | */ |
20 | 20 | public function load($resource, $locale, $domain = 'messages') |
21 | 21 | { |
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()); |
39 | 27 | } |
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]; |
45 | 31 | } |
46 | 32 |
|
47 | 33 | return $catalogue; |
|
0 commit comments