Completed
Push — development ( 13a157...98ea90 )
by Thomas
24s
created

TranslationService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A trans() 0 4 1
A transChoice() 0 4 1
A setLocale() 0 4 1
A getLocale() 0 4 1
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
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$parameters" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$domain" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$locale" missing
Loading history...
32
     * @inheritdoc
0 ignored issues
show
introduced by
Unexpected tag type @inheritdoc in doc block, expected @inheritDoc
Loading history...
33
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
34
    public function trans($id, array $parameters = [], $domain = null, $locale = null)
35
    {
36
        return $this->translator->trans($id, $parameters, $domain, $locale);
37
    }
38
39
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$number" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$parameters" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$domain" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$locale" missing
Loading history...
40
     * @inheritdoc
0 ignored issues
show
introduced by
Unexpected tag type @inheritdoc in doc block, expected @inheritDoc
Loading history...
41
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
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
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$locale" missing
Loading history...
48
     * @inheritdoc
0 ignored issues
show
introduced by
Unexpected tag type @inheritdoc in doc block, expected @inheritDoc
Loading history...
49
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
50
    public function setLocale($locale)
51
    {
52
        return $this->translator->setLocale($locale);
53
    }
54
55
    /**
56
     * @inheritdoc
0 ignored issues
show
introduced by
Unexpected tag type @inheritdoc in doc block, expected @inheritDoc
Loading history...
57
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
58
    public function getLocale()
59
    {
60
        return $this->translator->getLocale();
61
    }
62
}
63