Completed
Push — dev-master ( f1d44b...511541 )
by Derek Stephen
01:34
created

Translate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bone\Mvc\View\Extension\Plates;
4
5
use League\Plates\Engine;
6
use League\Plates\Extension\ExtensionInterface;
7
use Locale;
8
use Laminas\I18n\Translator\Translator;
9
10
class Translate implements ExtensionInterface
11
{
12
    /** @var Translator $translator */
13
    private $translator;
14
15
    /**
16
     * Translate constructor.
17
     * @param Translator $translator
18
     */
19 10
    public function __construct(Translator $translator)
20
    {
21 10
        $this->translator = $translator;
22 10
    }
23
24
    /**
25
     * @param Engine $engine
26
     */
27 9
    public function register(Engine $engine)
28
    {
29 9
        $engine->registerFunction('t', [$this, 'translate']);
30 9
        $engine->registerFunction('translate', [$this, 'translate']);
31 9
    }
32
33
    /**
34
     * @param string $string
35
     * @param string $domain
36
     * @return string
37
     */
38 1
    public function translate(string $string, string $domain = 'default') : string
39
    {
40 1
        return $this->translator->translate($string, $domain, Locale::getDefault());
41
    }
42
}
43