1 <?php
2 /**
3 * Copyright 2016 Klarna AB.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 namespace Klarna\XMLRPC;
18
19 /**
20 * Language Constants class.
21 */
22 class Language
23 {
24 /**
25 * Language constant for Danish (DA).<br>
26 * ISO639_DA.
27 *
28 * @var int
29 */
30 const DA = 27;
31
32 /**
33 * Language constant for German (DE).<br>
34 * ISO639_DE.
35 *
36 * @var int
37 */
38 const DE = 28;
39
40 /**
41 * Language constant for English (EN).<br>
42 * ISO639_EN.
43 *
44 * @var int
45 */
46 const EN = 31;
47
48 /**
49 * Language constant for Finnish (FI).<br>
50 * ISO639_FI.
51 *
52 * @var int
53 */
54 const FI = 37;
55
56 /**
57 * Language constant for Norwegian (NB).<br>
58 * ISO639_NB.
59 *
60 * @var int
61 */
62 const NB = 97;
63
64 /**
65 * Language constant for Dutch (NL).<br>
66 * ISO639_NL.
67 *
68 * @var int
69 */
70 const NL = 101;
71
72 /**
73 * Language constant for Swedish (SV).<br>
74 * ISO639_SV.
75 *
76 * @var int
77 */
78 const SV = 138;
79
80 /**
81 * Converts a language code, e.g. 'de' to the Language constant.
82 *
83 * @param string $val language code
84 *
85 * @return int|null
86 */
87 public static function fromCode($val)
88 {
89 $val = strtoupper($val);
90 if (array_key_exists($val, self::$languages)) {
91 return self::$languages[$val];
92 }
93
94 return;
95 }
96
97 /**
98 * Converts a Language constant to the respective language code.
99 *
100 * @param int $val Language constant
101 *
102 * @return lowercase string|null
103 */
104 public static function getCode($val)
105 {
106 if (self::$languageFlip === array()) {
107 self::$languageFlip = array_flip(self::$languages);
108 }
109 if (array_key_exists($val, self::$languageFlip)) {
110 return strtolower(self::$languageFlip[$val]);
111 }
112
113 return;
114 }
115
116 /**
117 * Cache for the flipped language array.
118 *
119 * @var array
120 */
121 private static $languageFlip = array();
122
123 /**
124 * Array containing all languages and their KRED Code.
125 *
126 * @var array
127 */
128 private static $languages = array(
129 'AA' => 1, // Afar
130 'AB' => 2, // Abkhazian
131 'AE' => 3, // Avestan
132 'AF' => 4, // Afrikaans
133 'AM' => 5, // Amharic
134 'AR' => 6, // Arabic
135 'AS' => 7, // Assamese
136 'AY' => 8, // Aymara
137 'AZ' => 9, // Azerbaijani
138 'BA' => 10, // Bashkir
139 'BE' => 11, // Byelorussian; Belarusian
140 'BG' => 12, // Bulgarian
141 'BH' => 13, // Bihari
142 'BI' => 14, // Bislama
143 'BN' => 15, // Bengali; Bangla
144 'BO' => 16, // Tibetan
145 'BR' => 17, // Breton
146 'BS' => 18, // Bosnian
147 'CA' => 19, // Catalan
148 'CE' => 20, // Chechen
149 'CH' => 21, // Chamorro
150 'CO' => 22, // Corsican
151 'CS' => 23, // Czech
152 'CU' => 24, // Church Slavic
153 'CV' => 25, // Chuvash
154 'CY' => 26, // Welsh
155 'DA' => 27, // Danish
156 'DE' => 28, // German
157 'DZ' => 29, // Dzongkha; Bhutani
158 'EL' => 30, // Greek
159 'EN' => 31, // English
160 'EO' => 32, // Esperanto
161 'ES' => 33, // Spanish
162 'ET' => 34, // Estonian
163 'EU' => 35, // Basque
164 'FA' => 36, // Persian
165 'FI' => 37, // Finnish
166 'FJ' => 38, // Fijian; Fiji
167 'FO' => 39, // Faroese
168 'FR' => 40, // French
169 'FY' => 41, // Frisian
170 'GA' => 42, // Irish
171 'GD' => 43, // Scots; Gaelic
172 'GL' => 44, // Gallegan; Galician
173 'GN' => 45, // Guarani
174 'GU' => 46, // Gujarati
175 'GV' => 47, // Manx
176 'HA' => 48, // Hausa
177 'HE' => 49, // Hebrew (formerly iw)
178 'HI' => 50, // Hindi
179 'HO' => 51, // Hiri Motu
180 'HR' => 52, // Croatian
181 'HU' => 53, // Hungarian
182 'HY' => 54, // Armenian
183 'HZ' => 55, // Herero
184 'IA' => 56, // Interlingua
185 'ID' => 57, // Indonesian (formerly in)
186 'IE' => 58, // Interlingue
187 'IK' => 59, // Inupiak
188 'IO' => 60, // Ido
189 'IS' => 61, // Icelandic
190 'IT' => 62, // Italian
191 'IU' => 63, // Inuktitut
192 'JA' => 64, // Japanese
193 'JV' => 65, // Javanese
194 'KA' => 66, // Georgian
195 'KI' => 67, // Kikuyu
196 'KJ' => 68, // Kuanyama
197 'KK' => 69, // Kazakh
198 'KL' => 70, // Kalaallisut; Greenlandic
199 'KM' => 71, // Khmer; Cambodian
200 'KN' => 72, // Kannada
201 'KO' => 73, // Korean
202 'KS' => 74, // Kashmiri
203 'KU' => 75, // Kurdish
204 'KV' => 76, // Komi
205 'KW' => 77, // Cornish
206 'KY' => 78, // Kirghiz
207 'LA' => 79, // Latin
208 'LB' => 80, // Letzeburgesch
209 'LN' => 81, // Lingala
210 'LO' => 82, // Lao; Laotian
211 'LT' => 83, // Lithuanian
212 'LV' => 84, // Latvian; Lettish
213 'MG' => 85, // Malagasy
214 'MH' => 86, // Marshall
215 'MI' => 87, // Maori
216 'MK' => 88, // Macedonian
217 'ML' => 89, // Malayalam
218 'MN' => 90, // Mongolian
219 'MO' => 91, // Moldavian
220 'MR' => 92, // Marathi
221 'MS' => 93, // Malay
222 'MT' => 94, // Maltese
223 'MY' => 95, // Burmese
224 'NA' => 96, // Nauru
225 'NB' => 97, // Norwegian Bokmål
226 'ND' => 98, // Ndebele, North
227 'NE' => 99, // Nepali
228 'NG' => 100, // Ndonga
229 'NL' => 101, // Dutch
230 'NN' => 102, // Norwegian Nynorsk
231 'NO' => 103, // Norwegian
232 'NR' => 104, // Ndebele, South
233 'NV' => 105, // Navajo
234 'NY' => 106, // Chichewa; Nyanja
235 'OC' => 107, // Occitan; Provençal
236 'OM' => 108, // (Afan) Oromo
237 'OR' => 109, // Oriya
238 'OS' => 110, // Ossetian; Ossetic
239 'PA' => 111, // Panjabi; Punjabi
240 'PI' => 112, // Pali
241 'PL' => 113, // Polish
242 'PS' => 114, // Pashto, Pushto
243 'PT' => 115, // Portuguese
244 'QU' => 116, // Quechua
245 'RM' => 117, // Rhaeto-Romance
246 'RN' => 118, // Rundi; Kirundi
247 'RO' => 119, // Romanian
248 'RU' => 120, // Russian
249 'RW' => 121, // Kinyarwanda
250 'SA' => 122, // Sanskrit
251 'SC' => 123, // Sardinian
252 'SD' => 124, // Sindhi
253 'SE' => 125, // Northern Sami
254 'SG' => 126, // Sango; Sangro
255 'SI' => 127, // Sinhalese
256 'SK' => 128, // Slovak
257 'SL' => 129, // Slovenian
258 'SM' => 130, // Samoan
259 'SN' => 131, // Shona
260 'SO' => 132, // Somali
261 'SQ' => 133, // Albanian
262 'SR' => 134, // Serbian
263 'SS' => 135, // Swati; Siswati
264 'ST' => 136, // Sesotho; Sotho, Southern
265 'SU' => 137, // Sundanese
266 'SV' => 138, // Swedish
267 'SW' => 139, // Swahili
268 'TA' => 140, // Tamil
269 'TE' => 141, // Telugu
270 'TG' => 142, // Tajik
271 'TH' => 143, // Thai
272 'TI' => 144, // Tigrinya
273 'TK' => 145, // Turkmen
274 'TL' => 146, // Tagalog
275 'TN' => 147, // Tswana; Setswana
276 'TO' => 148, // Tongan
277 'TR' => 149, // Turkish
278 'TS' => 150, // Tsonga
279 'TT' => 151, // Tatar
280 'TW' => 152, // Twi
281 'TY' => 153, // Tahitian
282 'UG' => 154, // Uighur
283 'UK' => 155, // Ukrainian
284 'UR' => 156, // Urdu
285 'UZ' => 157, // Uzbek
286 'VI' => 158, // Vietnamese
287 'VO' => 159, // Volapuk
288 'WA' => 160, // Walloon
289 'WO' => 161, // Wolof
290 'XH' => 162, // Xhosa
291 'YI' => 163, // Yiddish (formerly ji)
292 'YO' => 164, // Yoruba
293 'ZA' => 165, // Zhuang
294 'ZH' => 166, // Chinese
295 'ZU' => 167, // Zulu
296 );
297 }
298