Translate   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A en() 0 26 1
A messages() 0 13 3
A ru() 0 60 3
1
<?php
2
3
namespace dominus77\maintenance\widgets\timer;
4
5
/**
6
 * Class Translate
7
 * @see https://i18njs.com/
8
 * @package dominus77\maintenance\widgets\timer
9
 */
10
class Translate
11
{
12
    const LOCALE_EN = 'en';
13
    const LOCALE_RU = 'ru';
14
15
    /**
16
     * Switch Locale
17
     * @param string $locale
18
     * @return array
19
     */
20
    public static function messages($locale)
21
    {
22
        switch ($locale) {
23
            case self::LOCALE_EN:
24
                $data = self::en();
25
                break;
26
            case self::LOCALE_RU:
27
                $data = self::ru();
28
                break;
29
            default:
30
                $data = self::en();
31
        }
32
        return $data;
33
    }
34
35
    /**
36
     * Locale en
37
     * @return array
38
     */
39
    protected static function en()
40
    {
41
        $n = '%n ';
42
        return [
43
            'values' => [
44
                'and' => 'and',
45
                'Left' => 'Left',
46
                $n . 'days' => [
47
                    [0, 0, $n . 'days'],
48
                    [1, 1, $n . 'day'],
49
                    [2, null, $n . 'days']
50
                ],
51
                $n . 'hours' => [
52
                    [0, 0, $n . 'hours'],
53
                    [1, 1, $n . 'hour'],
54
                    [2, null, $n . 'hours']
55
                ],
56
                $n . 'minutes' => [
57
                    [0, 0, $n . 'minutes'],
58
                    [1, 1, $n . 'minute'],
59
                    [2, null, $n . 'minutes']
60
                ],
61
                $n . 'seconds' => [
62
                    [0, 0, $n . 'seconds'],
63
                    [1, 1, $n . 'second'],
64
                    [2, null, $n . 'seconds']
65
                ]
66
            ]
67
        ];
68
    }
69
70
    /**
71
     * Locale ru
72
     * @return array
73
     */
74
    protected static function ru()
75
    {
76
        $result = [
77
            'values' => [
78
                'and' => 'и',
79
                'Left' => 'Осталось'
80
            ]
81
        ];
82
83
        $n = '%n ';
84
        $values = [
85
            $n . 'days' => [
86
                0 => $n . 'дней',
87
                1 => $n . 'день',
88
                2 => $n . 'дня',
89
            ],
90
            $n . 'hours' => [
91
                0 => $n . 'часов',
92
                1 => $n . 'час',
93
                2 => $n . 'часа',
94
            ],
95
            $n . 'minutes' => [
96
                0 => $n . 'минут',
97
                1 => $n . 'минута',
98
                2 => $n . 'минуты',
99
            ],
100
            $n . 'seconds' => [
101
                0 => $n . 'секунд',
102
                1 => $n . 'секунда',
103
                2 => $n . 'секунды',
104
            ]
105
        ];
106
107
        foreach ($values as $key => $value) {
108
            foreach ($value as $count => $item) {
109
                $result['values'][$key] = [
110
                    [0, 0, $values[$key][0]],
111
                    [1, 1, $values[$key][1]],
112
                    [5, 20, $values[$key][0]],
113
                    [21, 21, $values[$key][1]],
114
                    [25, 30, $values[$key][0]],
115
                    [31, 31, $values[$key][1]],
116
                    [35, 40, $values[$key][0]],
117
                    [41, 41, $values[$key][1]],
118
                    [45, 50, $values[$key][0]],
119
                    [51, 51, $values[$key][1]],
120
                    [55, 60, $values[$key][0]],
121
                    [61, 61, $values[$key][1]],
122
                    [65, 70, $values[$key][0]],
123
                    [71, 71, $values[$key][1]],
124
                    [75, 80, $values[$key][0]],
125
                    [81, 81, $values[$key][1]],
126
                    [85, 90, $values[$key][0]],
127
                    [91, 91, $values[$key][1]],
128
                    [95, 100, $values[$key][0]],
129
                    [2, null, $values[$key][2]]
130
                ];
131
            }
132
        }
133
        return $result;
134
    }
135
}
136