-
Notifications
You must be signed in to change notification settings - Fork 190
/
Loader.php
45 lines (38 loc) · 1.25 KB
/
Loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Kunstmaan\TranslatorBundle\Service\Translator;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\MessageCatalogue;
/**
* Translation Loader
* Loads translations from the defined stasher
*/
class Loader implements LoaderInterface
{
private $translationRepository;
private $catalogues = [];
/**
* @return MessageCatalogue
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!isset($this->catalogues[$locale])) {
$catalogue = new MessageCatalogue($locale);
$translations = $this->translationRepository->findBy(['locale' => $locale]);
foreach ($translations as $translation) {
$catalogue->set(
(string) $translation->getKeyword(),
(string) $translation->getText(),
(string) $translation->getDomain()
);
}
$this->catalogues[$locale] = $catalogue;
} else {
$catalogue = $this->catalogues[$locale];
}
return $catalogue;
}
public function setTranslationRepository($translationRepository)
{
$this->translationRepository = $translationRepository;
}
}