Completed
Push — master ( 5e1d37...9b264a )
by Beñat
04:46
created

Translator::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the WPSymfonyForm plugin.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[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 LIN3S\WPSymfonyForm\Translation;
13
14
use Symfony\Component\Translation\Loader\XliffFileLoader;
15
use Symfony\Component\Translation\Translator as BaseTranslator;
16
17
/**
18
 * Translator singleton class.
19
 *
20
 * @author Gorka Laucirica <[email protected]>
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class Translator
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
24
{
25
    /**
26
     * The instance.
27
     *
28
     * @var self
29
     */
30
    private static $instance;
31
32
    /**
33
     * The factory method that returns the
34
     * instance of class in a singleton way.
35
     *
36
     * @return static
37
     */
38
    public static function instance()
39
    {
40
        if (!self::$instance) {
41
            self::$instance = new static();
42
        }
43
44
        return self::$instance;
45
    }
46
47
    /**
48
     * Protected facade.
49
     *
50
     * @return Translator
51
     */
52
    protected function create()
53
    {
54
        $translator = new BaseTranslator(ICL_LANGUAGE_CODE);
55
        $translator->addLoader('xlf', new XliffFileLoader());
56
57
        $languages = ['en', 'es', 'eu'];
58
59
        foreach ($languages as $language) {
60
            $translator->addResource(
61
                'xlf',
62
                ABSPATH . '/../vendor/symfony/validator/Resources/translations/validators.' . $language . '.xlf',
63
                $language,
64
                'validators'
65
            );
66
        }
67
68
        return $translator;
69
    }
70
71
    /**
72
     * This class cannot be instantiated.
73
     */
74
    private function __construct()
75
    {
76
    }
77
}
78