1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
namespace hexydec\agentzero; |
4
|
|
|
|
5
|
|
|
class languages { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Generates a configuration array for matching languages |
9
|
|
|
* |
10
|
|
|
* @return array<string,props> An array with keys representing the string to match, and values a props object defining how to generate the match and which properties to set |
11
|
|
|
*/ |
12
|
98 |
|
public static function get() : array { |
13
|
1 |
|
$languages = [ |
14
|
1 |
|
'af' => 'Afrikaans', |
15
|
1 |
|
'sq' => 'Albanian', |
16
|
1 |
|
'ar' => 'Arabic (Standard)', |
17
|
1 |
|
'hy' => 'Armenian', |
18
|
1 |
|
'as' => 'Assamese', |
19
|
1 |
|
'ast' => 'Asturian', |
20
|
1 |
|
'az' => 'Azerbaijani', |
21
|
1 |
|
'eu' => 'Basque', |
22
|
1 |
|
'bg' => 'Bulgarian', |
23
|
1 |
|
'be' => 'Belarusian', |
24
|
1 |
|
'bn' => 'Bengali', |
25
|
1 |
|
'bs' => 'Bosnian', |
26
|
1 |
|
'br' => 'Breton', |
27
|
1 |
|
'my' => 'Burmese', |
28
|
1 |
|
'ca' => 'Catalan', |
29
|
1 |
|
'ch' => 'Chamorro', |
30
|
1 |
|
'ce' => 'Chechen', |
31
|
1 |
|
'zh' => 'Chinese', |
32
|
1 |
|
'cv' => 'Chuvash', |
33
|
1 |
|
'co' => 'Corsican', |
34
|
1 |
|
'cr' => 'Cree', |
35
|
1 |
|
'hr' => 'Croatian', |
36
|
1 |
|
'cs' => 'Czech', |
37
|
1 |
|
'da' => 'Danish', |
38
|
1 |
|
'nl' => 'Dutch (Standard)', |
39
|
1 |
|
'en' => 'English', |
40
|
1 |
|
'eo' => 'Esperanto', |
41
|
1 |
|
'et' => 'Estonian', |
42
|
1 |
|
'fo' => 'Faeroese', |
43
|
1 |
|
'fa' => 'Farsi', |
44
|
1 |
|
'fj' => 'Fijian', |
45
|
1 |
|
'fi' => 'Finnish', |
46
|
1 |
|
'fr' => 'French (Standard)', |
47
|
1 |
|
'fy' => 'Frisian', |
48
|
1 |
|
'fur' => 'Friulian', |
49
|
1 |
|
'gd' => 'Gaelic (Scots)', |
50
|
1 |
|
'gl' => 'Galacian', |
51
|
1 |
|
'ka' => 'Georgian', |
52
|
1 |
|
'de' => 'German (Standard)', |
53
|
1 |
|
'el' => 'Greek', |
54
|
1 |
|
'gu' => 'Gujurati', |
55
|
1 |
|
'ht' => 'Haitian', |
56
|
1 |
|
'he' => 'Hebrew', |
57
|
1 |
|
'hi' => 'Hindi', |
58
|
1 |
|
'hu' => 'Hungarian', |
59
|
1 |
|
'is' => 'Icelandic', |
60
|
1 |
|
'id' => 'Indonesian', |
61
|
1 |
|
'iu' => 'Inuktitut', |
62
|
1 |
|
'ga' => 'Irish', |
63
|
1 |
|
'it' => 'Italian (Standard)', |
64
|
1 |
|
'ja' => 'Japanese', |
65
|
1 |
|
'kn' => 'Kannada', |
66
|
1 |
|
'ks' => 'Kashmiri', |
67
|
1 |
|
'kk' => 'Kazakh', |
68
|
1 |
|
'km' => 'Khmer', |
69
|
1 |
|
'ky' => 'Kirghiz', |
70
|
1 |
|
'tlh' => 'Klingon', |
71
|
1 |
|
'ko' => 'Korean', |
72
|
1 |
|
'la' => 'Latin', |
73
|
1 |
|
'lv' => 'Latvian', |
74
|
1 |
|
'lt' => 'Lithuanian', |
75
|
1 |
|
'lb' => 'Luxembourgish', |
76
|
1 |
|
'mk' => 'FYRO Macedonian', |
77
|
1 |
|
'ms' => 'Malay', |
78
|
1 |
|
'ml' => 'Malayalam', |
79
|
1 |
|
'mt' => 'Maltese', |
80
|
1 |
|
'mi' => 'Maori', |
81
|
1 |
|
'mr' => 'Marathi', |
82
|
1 |
|
'mo' => 'Moldavian', |
83
|
1 |
|
'nv' => 'Navajo', |
84
|
1 |
|
'ng' => 'Ndonga', |
85
|
1 |
|
'ne' => 'Nepali', |
86
|
1 |
|
'no' => 'Norwegian', |
87
|
1 |
|
'nb' => 'Norwegian (Bokmal)', |
88
|
1 |
|
'nn' => 'Norwegian (Nynorsk)', |
89
|
1 |
|
'oc' => 'Occitan', |
90
|
1 |
|
'or' => 'Oriya', |
91
|
1 |
|
'om' => 'Oromo', |
92
|
1 |
|
'pl' => 'Polish', |
93
|
1 |
|
'pt' => 'Portuguese', |
94
|
1 |
|
'pa' => 'Punjabi', |
95
|
1 |
|
'qu' => 'Quechua', |
96
|
1 |
|
'rm' => 'Rhaeto-Romanic', |
97
|
1 |
|
'ro' => 'Romanian', |
98
|
1 |
|
'ru' => 'Russian', |
99
|
1 |
|
'sz' => 'Sami (Lappish)', |
100
|
1 |
|
'sg' => 'Sango', |
101
|
1 |
|
'sa' => 'Sanskrit', |
102
|
1 |
|
'sc' => 'Sardinian', |
103
|
1 |
|
'sd' => 'Sindhi', |
104
|
1 |
|
'si' => 'Singhalese', |
105
|
1 |
|
'sr' => 'Serbian', |
106
|
1 |
|
'sk' => 'Slovak', |
107
|
1 |
|
'sl' => 'Slovenian', |
108
|
1 |
|
'so' => 'Somani', |
109
|
1 |
|
'sb' => 'Sorbian', |
110
|
1 |
|
'es' => 'Spanish', |
111
|
1 |
|
'sx' => 'Sutu', |
112
|
1 |
|
'sw' => 'Swahili', |
113
|
1 |
|
'sv' => 'Swedish', |
114
|
1 |
|
'ta' => 'Tamil', |
115
|
1 |
|
'tt' => 'Tatar', |
116
|
1 |
|
'te' => 'Teluga', |
117
|
1 |
|
'th' => 'Thai', |
118
|
1 |
|
'tig' => 'Tigre', |
119
|
1 |
|
'ts' => 'Tsonga', |
120
|
1 |
|
'tn' => 'Tswana', |
121
|
1 |
|
'tr' => 'Turkish', |
122
|
1 |
|
'tk' => 'Turkmen', |
123
|
1 |
|
'uk' => 'Ukrainian', |
124
|
1 |
|
'hsb' => 'Upper Sorbian', |
125
|
1 |
|
'ur' => 'Urdu', |
126
|
1 |
|
've' => 'Venda', |
127
|
1 |
|
'vi' => 'Vietnamese', |
128
|
1 |
|
'vo' => 'Volapuk', |
129
|
1 |
|
'wa' => 'Walloon', |
130
|
1 |
|
'cy' => 'Welsh', |
131
|
1 |
|
'xh' => 'Xhosa', |
132
|
1 |
|
'ji' => 'Yiddish', |
133
|
1 |
|
'zu' => 'Zulu', |
134
|
1 |
|
'in' => 'India' |
135
|
1 |
|
]; |
136
|
1 |
|
$fn = function (string $value, int $i, array $tokens, string $match) : ?array { |
137
|
98 |
|
if ($value === $match) { |
138
|
11 |
|
return ['language' => $value]; |
139
|
|
|
} else { |
140
|
98 |
|
$len = \strlen($match); |
141
|
98 |
|
$value = \str_replace('_', '-', $value); |
142
|
98 |
|
$letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
143
|
98 |
|
if (\str_starts_with($value, $match.'-') && \strlen($value) === $len + 3 && \strspn($value, $letters, $len + 1, 2) === 2) { |
144
|
43 |
|
return ['language' => $match.'-'.\strtoupper(\substr($value, $len + 1, 2))]; |
145
|
|
|
} |
146
|
|
|
} |
147
|
97 |
|
return null; |
148
|
1 |
|
}; |
149
|
9 |
|
$lang = function (string $value) use ($languages): ?array { |
150
|
8 |
|
$value = \str_replace('_', '-', \explode('/', $value)[1]); |
151
|
8 |
|
$lang = \mb_strtolower(\mb_substr($value, 0, 2)); |
152
|
8 |
|
$len = \mb_strlen($value); |
153
|
8 |
|
if (isset($languages[$lang]) && \in_array($len, [2, 5, 10], true)) { |
154
|
8 |
|
if ($len > 2 && \mb_strpos($value, '-') === 2) { |
155
|
7 |
|
if ($len === 5) { |
156
|
6 |
|
$suffix = '-'.\strtoupper(\mb_substr($value, 3, 2)); |
157
|
2 |
|
} elseif (\mb_strpos($value, '-', 3) === 7) { |
158
|
2 |
|
$suffix = '-'.\strtoupper(\mb_substr($value, 8, 2)); |
159
|
|
|
} |
160
|
|
|
} |
161
|
8 |
|
return ['language' => $lang.($suffix ?? '')]; |
162
|
|
|
} |
163
|
|
|
return null; |
164
|
9 |
|
}; |
165
|
1 |
|
$config = [ |
166
|
1 |
|
'Language/' => new props('start', $lang), |
167
|
1 |
|
'ByteLocale/' => new props('start', $lang), |
168
|
1 |
|
'ByteFullLocale/' => new props('start', $lang), |
169
|
1 |
|
'FBLC/' => new props('start', $lang), |
170
|
1 |
|
]; |
171
|
1 |
|
foreach (\array_keys($languages) AS $key) { |
172
|
1 |
|
$config[$key] = new props('start', $fn); |
173
|
|
|
} |
174
|
1 |
|
return $config; |
175
|
|
|
} |
176
|
|
|
} |