1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OcLegacy\Translation; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Translation\Loader\YamlFileLoader; |
6
|
|
|
use Symfony\Component\Translation\MessageSelector; |
7
|
|
|
use Symfony\Component\Translation\Translator; |
8
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
9
|
|
|
|
10
|
|
|
class TranslationService implements TranslatorInterface |
11
|
|
|
{ |
12
|
|
|
private $translator; |
13
|
|
|
|
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
$translator = new Translator('de', new MessageSelector()); |
17
|
|
|
$translator->setFallbackLocales(['en']); |
18
|
|
|
|
19
|
|
|
$yamlLoader = new YamlFileLoader(); |
20
|
|
|
$translator->addLoader('yml', $yamlLoader); |
21
|
|
|
|
22
|
|
|
foreach (['de', 'fr', 'nl', 'es', 'pl', 'it', 'ru'] as $languageKey) { |
23
|
|
|
$translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/constants.' . $languageKey . '.yml', $languageKey); |
24
|
|
|
$translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/messages.' . $languageKey . '.yml', $languageKey); |
25
|
|
|
$translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/validators.' . $languageKey . '.yml', $languageKey); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->translator = $translator; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
|
|
|
|
32
|
|
|
* @inheritdoc |
|
|
|
|
33
|
|
|
*/ |
|
|
|
|
34
|
|
|
public function trans($id, array $parameters = [], $domain = null, $locale = null) |
35
|
|
|
{ |
36
|
|
|
return $this->translator->trans($id, $parameters, $domain, $locale); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* @inheritdoc |
|
|
|
|
41
|
|
|
*/ |
|
|
|
|
42
|
|
|
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null) |
43
|
|
|
{ |
44
|
|
|
return $this->translator->transChoice($id, $number, $parameters, $domain, $locale); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
|
|
|
|
48
|
|
|
* @inheritdoc |
|
|
|
|
49
|
|
|
*/ |
|
|
|
|
50
|
|
|
public function setLocale($locale) |
51
|
|
|
{ |
52
|
|
|
return $this->translator->setLocale($locale); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritdoc |
|
|
|
|
57
|
|
|
*/ |
|
|
|
|
58
|
|
|
public function getLocale() |
59
|
|
|
{ |
60
|
|
|
return $this->translator->getLocale(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|