Translator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
eloc 30
c 4
b 0
f 2
dl 0
loc 54
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A trans() 0 21 5
A transChoice() 0 22 5
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://www.zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\FrameworkExtraBundle\Translation;
8
9
use Symfony\Bundle\FrameworkBundle\Translation\Translator as BaseTranslator;
10
11
/**
12
 * Provides zz locale
13
 *
14
 * To enable this feature the default translator class must be replaced by adding the following to config.yml:
15
 * > parameters:
16
 * >     translator.class: 'Zicht\Bundle\FrameworkExtraBundle\Translation\Translator'
17
 *
18
 * Class Translator
19
 *
20
 * @package Zicht\Bundle\FrameworkExtraBundle\Translation
21
 */
22
class Translator extends BaseTranslator
23
{
24
    /**
25
     * @{inheritDoc}
26
     */
27
    public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
28
    {
29
        if (null === $locale) {
30
            $locale = $this->getLocale();
31
        }
32
33
        if ($locale == 'zz') {
34
            if (null === $domain) {
35
                $domain = 'messages';
36
            }
37
            $parts = array(
38
                sprintf('{%s', $id),
39
                sprintf('@%s', $domain),
40
            );
41
            if (!empty($parameters)) {
42
                $parts [] = json_encode($parameters);
43
            }
44
            $parts [] = '}';
45
            return join('', $parts);
46
        } else {
47
            return parent::trans($id, $parameters, $domain, $locale);
48
        }
49
    }
50
51
    /**
52
     * @{inheritDoc}
53
     */
54
    public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
55
    {
56
        if (null === $locale) {
57
            $locale = $this->getLocale();
58
        }
59
60
        if ($locale == 'zz') {
61
            if (null === $domain) {
62
                $domain = 'messages';
63
            }
64
            $parts = array(
65
                sprintf('{%s', $id),
66
                sprintf('#%s', $number),
67
                sprintf('@%s', $domain),
68
            );
69
            if (!empty($parameters)) {
70
                $parts [] = sprintf('[%s]', join(', ', array_keys($parameters)));
71
            }
72
            $parts [] = '}';
73
            return join('', $parts);
74
        } else {
75
            return parent::transChoice($id, $number, $parameters, $domain, $locale);
76
        }
77
    }
78
}
79