Translate::translate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Bone\I18n\View\Extension;
4
5
use Laminas\I18n\Translator\Translator;
6
use League\Plates\Engine;
7
use League\Plates\Extension\ExtensionInterface;
8
use Locale;
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 4
    public function __construct(Translator $translator)
20
    {
21 4
        $this->translator = $translator;
22 4
    }
23
24
    /**
25
     * @param Engine $engine
26
     */
27 4
    public function register(Engine $engine)
28
    {
29 4
        $engine->registerFunction('t', [$this, 'translate']);
30 4
        $engine->registerFunction('translate', [$this, 'translate']);
31 4
    }
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