Completed
Push — master ( 2effa3...c35cd4 )
by Michal
39:30 queued 33:04
created

Translator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 16.66%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 61
ccs 3
cts 18
cp 0.1666
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 23 3
A gettext() 0 10 2
1
<?php
2
3
/**
4
 * Defines the localization helper infrastructure of the library.
5
 */
6
7
namespace PhpMyAdmin\SqlParser;
8
9
class Translator
10
{
11
    /**
12
     * The MoTranslator loader object.
13
     *
14
     * @var \PhpMyAdmin\MoTranslator\Loader
15
     */
16
    private static $loader;
17
18
    /**
19
     * The MoTranslator translator object.
20
     *
21
     * @var \PhpMyAdmin\MoTranslator\Translator
22
     */
23
    private static $translator;
24
25
    /**
26
     * Loads transator.
27
     */
28
    public static function load()
29
    {
30
        if (is_null(self::$loader)) {
31
            // Create loader object
32
            self::$loader = new \PhpMyAdmin\MoTranslator\Loader();
33
34
            // Set locale
35
            self::$loader->setlocale(
36
                self::$loader->detectlocale()
37
            );
38
39
            // Set default text domain
40
            self::$loader->textdomain('sqlparser');
41
42
            // Set path where to look for a domain
43
            self::$loader->bindtextdomain('sqlparser', __DIR__ . '/../locale/');
44
        }
45
46
        if (is_null(self::$translator)) {
47
            // Get translator
48
            self::$translator = self::$loader->getTranslator();
49
        }
50
    }
51
52
    /**
53
     * Translates a string.
54
     *
55
     * @param string $msgid String to be translated
56
     *
57
     * @return string translated string (or original, if not found)
58
     */
59 87
    public static function gettext($msgid)
60
    {
61 87
        if (!class_exists('\PhpMyAdmin\MoTranslator\Loader', true)) {
62 87
            return $msgid;
63
        }
64
65
        self::load();
66
67
        return self::$translator->gettext($msgid);
68
    }
69
}
70