1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the badams\MicrosoftTranslator library |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/MIT |
6
|
|
|
* @link https://github.com/badams/microsoft-translator |
7
|
|
|
* @package badams/microsoft-translator |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace badams\MicrosoftTranslator; |
14
|
|
|
|
15
|
|
|
use badams\MicrosoftTranslator\Exceptions\UnsupportedLanguageException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Language |
19
|
|
|
* @package badams\MicrosoftTranslator |
20
|
|
|
*/ |
21
|
|
|
class Language |
22
|
|
|
{ |
23
|
|
|
const ARABIC = 'ar'; |
24
|
|
|
const BOSNIAN_LATIN = 'bs-latn'; |
25
|
|
|
const BULGARIAN = 'bg'; |
26
|
|
|
const CATALAN = 'ca'; |
27
|
|
|
const CHINESE_SIMPLIFIED = 'zh-chs'; |
28
|
|
|
const CHINESE_TRADITIONAL = 'zh-cht'; |
29
|
|
|
const CROATIAN = 'hr'; |
30
|
|
|
const CZECH = 'cs'; |
31
|
|
|
const DANISH = 'da'; |
32
|
|
|
const DUTCH = 'nl'; |
33
|
|
|
const ENGLISH = 'en'; |
34
|
|
|
const ESTONIAN = 'et'; |
35
|
|
|
const FINNISH = 'fi'; |
36
|
|
|
const FRENCH = 'fr'; |
37
|
|
|
const GERMAN = 'de'; |
38
|
|
|
const GREEK = 'el'; |
39
|
|
|
const HAITIAN_CREOLE = 'ht'; |
40
|
|
|
const HEBREW = 'he'; |
41
|
|
|
const HINDI = 'hi'; |
42
|
|
|
const HMONG_DAW = 'mww'; |
43
|
|
|
const HUNGARIAN = 'hu'; |
44
|
|
|
const INDONESIAN = 'id'; |
45
|
|
|
const ITALIAN = 'it'; |
46
|
|
|
const JAPANESE = 'ja'; |
47
|
|
|
const KISWAHILI = 'sw'; |
48
|
|
|
const KLINGON = 'tlh'; |
49
|
|
|
const KLINGON_PIQAD = 'tlh-qaak'; |
50
|
|
|
const KOREAN = 'ko'; |
51
|
|
|
const LATVIAN = 'lv'; |
52
|
|
|
const LITHUANIAN = 'lt'; |
53
|
|
|
const MALAY = 'ms'; |
54
|
|
|
const MALTESE = 'mt'; |
55
|
|
|
const NORWEGIAN = 'no'; |
56
|
|
|
const PERSIAN = 'fa'; |
57
|
|
|
const POLISH = 'pl'; |
58
|
|
|
const PORTUGUESE = 'pt'; |
59
|
|
|
const QUERETARO_OTOMI = 'otq'; |
60
|
|
|
const ROMANIAN = 'ro'; |
61
|
|
|
const RUSSIAN = 'ru'; |
62
|
|
|
const SERBIAN_CYRILLIC = 'sr-cyrl'; |
63
|
|
|
const SERBIAN_LATIN = 'sr-latn'; |
64
|
|
|
const SLOVAK = 'sk'; |
65
|
|
|
const SLOVENIAN = 'sl'; |
66
|
|
|
const SPANISH = 'es'; |
67
|
|
|
const SWEDISH = 'sv'; |
68
|
|
|
const THAI = 'th'; |
69
|
|
|
const TURKISH = 'tr'; |
70
|
|
|
const UKRAINIAN = 'uk'; |
71
|
|
|
const URDU = 'ur'; |
72
|
|
|
const VIETNAMESE = 'vi'; |
73
|
|
|
const WELSH = 'cy'; |
74
|
|
|
const YUCATEC_MAYA = 'yua'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
protected $code; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* List of officially supported language code |
83
|
|
|
* |
84
|
|
|
* @var array |
85
|
|
|
*/ |
86
|
|
|
private $languages = [ |
87
|
|
|
self::ARABIC => 'Arabic', |
88
|
|
|
self::BOSNIAN_LATIN => 'Bosnian (Latin)', |
89
|
|
|
self::BULGARIAN => 'Bulgarian', |
90
|
|
|
self::CATALAN => 'Catalan', |
91
|
|
|
self::CHINESE_SIMPLIFIED => 'Chinese Simplified', |
92
|
|
|
self::CHINESE_TRADITIONAL => 'Chinese Traditional', |
93
|
|
|
self::CROATIAN => 'Croatian', |
94
|
|
|
self::CZECH => 'Czech', |
95
|
|
|
self::DANISH => 'Danish', |
96
|
|
|
self::DUTCH => 'Dutch', |
97
|
|
|
self::ENGLISH => 'English', |
98
|
|
|
self::ESTONIAN => 'Estonian', |
99
|
|
|
self::FINNISH => 'Finnish', |
100
|
|
|
self::FRENCH => 'French', |
101
|
|
|
self::GERMAN => 'German', |
102
|
|
|
self::GREEK => 'Greek', |
103
|
|
|
self::HAITIAN_CREOLE => 'Haitian Creole', |
104
|
|
|
self::HEBREW => 'Hebrew', |
105
|
|
|
self::HINDI => 'Hindi', |
106
|
|
|
self::HMONG_DAW => 'Hmong Daw', |
107
|
|
|
self::HUNGARIAN => 'Hungarian', |
108
|
|
|
self::INDONESIAN => 'Indonesian', |
109
|
|
|
self::ITALIAN => 'Italian', |
110
|
|
|
self::JAPANESE => 'Japanese', |
111
|
|
|
self::KISWAHILI => 'Kiswahili', |
112
|
|
|
self::KLINGON => 'Klingon', |
113
|
|
|
self::KLINGON_PIQAD => 'Klingon (pIqaD)', |
114
|
|
|
self::KOREAN => 'Korean', |
115
|
|
|
self::LATVIAN => 'Latvian', |
116
|
|
|
self::LITHUANIAN => 'Lithuanian', |
117
|
|
|
self::MALAY => 'Malay', |
118
|
|
|
self::MALTESE => 'Maltese', |
119
|
|
|
self::NORWEGIAN => 'Norwegian', |
120
|
|
|
self::PERSIAN => 'Persian', |
121
|
|
|
self::POLISH => 'Polish', |
122
|
|
|
self::PORTUGUESE => 'Portuguese', |
123
|
|
|
self::QUERETARO_OTOMI => 'Querétaro Otomi', |
124
|
|
|
self::ROMANIAN => 'Romanian', |
125
|
|
|
self::RUSSIAN => 'Russian', |
126
|
|
|
self::SERBIAN_CYRILLIC => 'Serbian (Cyrillic)', |
127
|
|
|
self::SERBIAN_LATIN => 'Serbian (Latin)', |
128
|
|
|
self::SLOVAK => 'Slovak', |
129
|
|
|
self::SLOVENIAN => 'Slovenian', |
130
|
|
|
self::SPANISH => 'Spanish', |
131
|
|
|
self::SWEDISH => 'Swedish', |
132
|
|
|
self::THAI => 'Thai', |
133
|
|
|
self::TURKISH => 'Turkish', |
134
|
|
|
self::UKRAINIAN => 'Ukrainian', |
135
|
|
|
self::URDU => 'Urdu', |
136
|
|
|
self::VIETNAMESE => 'Vietnamese', |
137
|
|
|
self::WELSH => 'Welsh', |
138
|
|
|
self::YUCATEC_MAYA => 'Yucatec Maya' |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Language constructor. |
143
|
|
|
* @param $code |
144
|
|
|
*/ |
145
|
87 |
|
public function __construct($code) |
146
|
|
|
{ |
147
|
87 |
|
$this->code = strtolower((string)$code); |
148
|
|
|
|
149
|
87 |
|
if (!array_key_exists($this->code, $this->languages)) { |
150
|
15 |
|
throw new UnsupportedLanguageException(sprintf('%s is not a supported language code', $this->code)); |
151
|
|
|
} |
152
|
72 |
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
45 |
|
public function __toString() |
158
|
|
|
{ |
159
|
45 |
|
return $this->code; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
6 |
|
public function getEnglishName() |
166
|
|
|
{ |
167
|
6 |
|
return $this->languages[$this->code]; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|