Completed
Push — master ( f339fb...41f35e )
by Filipe
08:39
created

I18n::getFunctions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 25
ccs 16
cts 16
cp 1
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/template package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Template\Extension;
11
12
use Slick\I18n\TranslateMethods;
13
use Slick\Template\EngineExtensionInterface;
14
15
/**
16
 * I18n extension for slick/template
17
 *
18
 * @package Slick\Template\Extension
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
class I18n extends AbstractTwigExtension implements EngineExtensionInterface
22
{
23
24
    /**
25
     * Adds translation methods to this class
26
     */
27
    use TranslateMethods;
28
29
    /**
30
     * Returns the name of the extension.
31
     *
32
     * @return string The extension name
33
     */
34 2
    public function getName()
35
    {
36 2
        return 'I18n extension';
37
    }
38
39
    /**
40
     * Returns a list of functions to add to the existing list.
41
     *
42
     * @return array An array of functions
43
     */
44 4
    public function getFunctions()
45
    {
46
        return [
47 4
            new \Twig_SimpleFunction(
48 4
                'translate',
49
                function ($message, $domain = null, $locale = null) {
50 2
                    return $this->translate($message, $domain, $locale);
51
                }
52 4
            ),
53 4
            new \Twig_SimpleFunction(
54 4
                'transPlural',
55 2
                function(
56
                    $singular, $plural, $number, $domain = null, $locale = null
57
                ) {
58 2
                    return $this->translatePlural(
59 2
                        $singular,
60 2
                        $plural,
61 2
                        $number,
62 2
                        $domain,
63
                        $locale
64 2
                    );
65
                }
66 4
            )
67 4
        ];
68
    }
69
}
70