TranslatorTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
dl 0
loc 24
c 1
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 11 4
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2021 WEBEWEB
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 WBW\Bundle\JQuery\DataTablesBundle\Translation;
13
14
use WBW\Bundle\CoreBundle\Translation\TranslatorTrait as BaseTranslatorTrait;
15
use WBW\Bundle\JQuery\DataTablesBundle\WBWJQueryDataTablesBundle;
16
17
/**
18
 * Translator trait.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\JQuery\DataTablesBundle\Translation
22
 */
23
trait TranslatorTrait {
24
25
    use BaseTranslatorTrait;
26
27
    /**
28
     * Translate.
29
     *
30
     * @param string|null $id The id.
31
     * @param array<string,mixed> $parameters Teh parameters.
32
     * @param string|null $domain The domain.
33
     * @param string|null $locale The locale.
34
     * @return string Returns the translated id in case of success, id otherwise.
35
     */
36
    protected function translate(?string $id, array $parameters = [], string $domain = null, string $locale = null): string {
37
38
        if (null === $id) {
39
            return "";
40
        }
41
42
        if (null === $domain) {
43
            $domain = WBWJQueryDataTablesBundle::getTranslationDomain();
44
        }
45
46
        return null !== $this->getTranslator() ? $this->getTranslator()->trans($id, $parameters, $domain, $locale) : $id;
47
    }
48
}
49