Translator::getLocale()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the AfDontTranslateBundle package
5
 *
6
 * (c) Antoine Froger <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code
10
 */
11
12
namespace Af\Bundle\DontTranslateBundle\Translation;
13
14
use Symfony\Component\Translation\TranslatorInterface;
15
16
/**
17
 * Class Translator
18
 *
19
 * @package Af\Bundle\DontTranslateBundle\Translation
20
 *
21
 * @author Antoine Froger <[email protected]>
22
 */
23
class Translator implements TranslatorInterface
24
{
25
    protected $translator;
26
27
    /** @var bool */
28
    protected $debug = false;
29
30
    public function __construct(TranslatorInterface $translator)
31
    {
32
        $this->translator = $translator;
33
    }
34
35
    /**
36
     * Sets the debug mode
37
     *
38
     * @param  bool $debug
39
     *
40
     * @return $this
41
     */
42
    public function setDebug($debug)
43
    {
44
        $this->debug = (bool)$debug;
45
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function trans($id, array $parameters = array(), $domain = null, $locale = null)
53
    {
54
        if ($this->debug) {
55
            return $id;
56
        }
57
58
        return $this->translator->trans($id, $parameters, $domain, $locale);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
65
    {
66
        if ($this->debug) {
67
            return $id;
68
        }
69
70
        return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function setLocale($locale)
77
    {
78
        $this->translator->setLocale($locale);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function getLocale()
85
    {
86
        return $this->translator->getLocale();
87
    }
88
}
89