Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Locale/CountryManager.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Locale; | |
4 | |
5 use Drupal\Core\Extension\ModuleHandlerInterface; | |
6 | |
7 /** | |
8 * Provides list of countries. | |
9 */ | |
10 class CountryManager implements CountryManagerInterface { | |
11 | |
12 /** | |
13 * The module handler service. | |
14 * | |
15 * @var \Drupal\Core\Extension\ModuleHandlerInterface | |
16 */ | |
17 protected $moduleHandler; | |
18 | |
19 /** | |
20 * An array of country code => country name pairs. | |
21 */ | |
22 protected $countries; | |
23 | |
24 /** | |
25 * Constructor. | |
26 * | |
27 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | |
28 */ | |
29 public function __construct(ModuleHandlerInterface $module_handler) { | |
30 $this->moduleHandler = $module_handler; | |
31 } | |
32 | |
33 /** | |
34 * Get an array of all two-letter country code => country name pairs. | |
35 * | |
36 * @return array | |
37 * An array of country code => country name pairs. | |
38 */ | |
39 public static function getStandardList() { | |
40 $countries = [ | |
41 'AC' => t('Ascension Island'), | |
42 'AD' => t('Andorra'), | |
43 'AE' => t('United Arab Emirates'), | |
44 'AF' => t('Afghanistan'), | |
45 'AG' => t('Antigua and Barbuda'), | |
46 'AI' => t('Anguilla'), | |
47 'AL' => t('Albania'), | |
48 'AM' => t('Armenia'), | |
49 'AN' => t('Netherlands Antilles'), | |
50 'AO' => t('Angola'), | |
51 'AQ' => t('Antarctica'), | |
52 'AR' => t('Argentina'), | |
53 'AS' => t('American Samoa'), | |
54 'AT' => t('Austria'), | |
55 'AU' => t('Australia'), | |
56 'AW' => t('Aruba'), | |
57 'AX' => t('Åland Islands'), | |
58 'AZ' => t('Azerbaijan'), | |
59 'BA' => t('Bosnia and Herzegovina'), | |
60 'BB' => t('Barbados'), | |
61 'BD' => t('Bangladesh'), | |
62 'BE' => t('Belgium'), | |
63 'BF' => t('Burkina Faso'), | |
64 'BG' => t('Bulgaria'), | |
65 'BH' => t('Bahrain'), | |
66 'BI' => t('Burundi'), | |
67 'BJ' => t('Benin'), | |
68 'BL' => t('Saint Barthélemy'), | |
69 'BM' => t('Bermuda'), | |
70 'BN' => t('Brunei'), | |
71 'BO' => t('Bolivia'), | |
72 'BQ' => t('Caribbean Netherlands'), | |
73 'BR' => t('Brazil'), | |
74 'BS' => t('Bahamas'), | |
75 'BT' => t('Bhutan'), | |
76 'BV' => t('Bouvet Island'), | |
77 'BW' => t('Botswana'), | |
78 'BY' => t('Belarus'), | |
79 'BZ' => t('Belize'), | |
80 'CA' => t('Canada'), | |
81 'CC' => t('Cocos [Keeling] Islands'), | |
82 'CD' => t('Congo - Kinshasa'), | |
83 'CF' => t('Central African Republic'), | |
84 'CG' => t('Congo - Brazzaville'), | |
85 'CH' => t('Switzerland'), | |
86 'CI' => t('Côte d’Ivoire'), | |
87 'CK' => t('Cook Islands'), | |
88 'CL' => t('Chile'), | |
89 'CM' => t('Cameroon'), | |
90 'CN' => t('China'), | |
91 'CO' => t('Colombia'), | |
92 'CP' => t('Clipperton Island'), | |
93 'CR' => t('Costa Rica'), | |
94 'CU' => t('Cuba'), | |
95 'CV' => t('Cape Verde'), | |
96 'CW' => t('Curaçao'), | |
97 'CX' => t('Christmas Island'), | |
98 'CY' => t('Cyprus'), | |
99 'CZ' => t('Czech Republic'), | |
100 'DE' => t('Germany'), | |
101 'DG' => t('Diego Garcia'), | |
102 'DJ' => t('Djibouti'), | |
103 'DK' => t('Denmark'), | |
104 'DM' => t('Dominica'), | |
105 'DO' => t('Dominican Republic'), | |
106 'DZ' => t('Algeria'), | |
107 'EA' => t('Ceuta and Melilla'), | |
108 'EC' => t('Ecuador'), | |
109 'EE' => t('Estonia'), | |
110 'EG' => t('Egypt'), | |
111 'EH' => t('Western Sahara'), | |
112 'ER' => t('Eritrea'), | |
113 'ES' => t('Spain'), | |
114 'ET' => t('Ethiopia'), | |
115 'FI' => t('Finland'), | |
116 'FJ' => t('Fiji'), | |
117 'FK' => t('Falkland Islands'), | |
118 'FM' => t('Micronesia'), | |
119 'FO' => t('Faroe Islands'), | |
120 'FR' => t('France'), | |
121 'GA' => t('Gabon'), | |
122 'GB' => t('United Kingdom'), | |
123 'GD' => t('Grenada'), | |
124 'GE' => t('Georgia'), | |
125 'GF' => t('French Guiana'), | |
126 'GG' => t('Guernsey'), | |
127 'GH' => t('Ghana'), | |
128 'GI' => t('Gibraltar'), | |
129 'GL' => t('Greenland'), | |
130 'GM' => t('Gambia'), | |
131 'GN' => t('Guinea'), | |
132 'GP' => t('Guadeloupe'), | |
133 'GQ' => t('Equatorial Guinea'), | |
134 'GR' => t('Greece'), | |
135 'GS' => t('South Georgia and the South Sandwich Islands'), | |
136 'GT' => t('Guatemala'), | |
137 'GU' => t('Guam'), | |
138 'GW' => t('Guinea-Bissau'), | |
139 'GY' => t('Guyana'), | |
140 'HK' => t('Hong Kong SAR China'), | |
141 'HM' => t('Heard Island and McDonald Islands'), | |
142 'HN' => t('Honduras'), | |
143 'HR' => t('Croatia'), | |
144 'HT' => t('Haiti'), | |
145 'HU' => t('Hungary'), | |
146 'IC' => t('Canary Islands'), | |
147 'ID' => t('Indonesia'), | |
148 'IE' => t('Ireland'), | |
149 'IL' => t('Israel'), | |
150 'IM' => t('Isle of Man'), | |
151 'IN' => t('India'), | |
152 'IO' => t('British Indian Ocean Territory'), | |
153 'IQ' => t('Iraq'), | |
154 'IR' => t('Iran'), | |
155 'IS' => t('Iceland'), | |
156 'IT' => t('Italy'), | |
157 'JE' => t('Jersey'), | |
158 'JM' => t('Jamaica'), | |
159 'JO' => t('Jordan'), | |
160 'JP' => t('Japan'), | |
161 'KE' => t('Kenya'), | |
162 'KG' => t('Kyrgyzstan'), | |
163 'KH' => t('Cambodia'), | |
164 'KI' => t('Kiribati'), | |
165 'KM' => t('Comoros'), | |
166 'KN' => t('Saint Kitts and Nevis'), | |
167 'KP' => t('North Korea'), | |
168 'KR' => t('South Korea'), | |
169 'KW' => t('Kuwait'), | |
170 'KY' => t('Cayman Islands'), | |
171 'KZ' => t('Kazakhstan'), | |
172 'LA' => t('Laos'), | |
173 'LB' => t('Lebanon'), | |
174 'LC' => t('Saint Lucia'), | |
175 'LI' => t('Liechtenstein'), | |
176 'LK' => t('Sri Lanka'), | |
177 'LR' => t('Liberia'), | |
178 'LS' => t('Lesotho'), | |
179 'LT' => t('Lithuania'), | |
180 'LU' => t('Luxembourg'), | |
181 'LV' => t('Latvia'), | |
182 'LY' => t('Libya'), | |
183 'MA' => t('Morocco'), | |
184 'MC' => t('Monaco'), | |
185 'MD' => t('Moldova'), | |
186 'ME' => t('Montenegro'), | |
187 'MF' => t('Saint Martin'), | |
188 'MG' => t('Madagascar'), | |
189 'MH' => t('Marshall Islands'), | |
190 'MK' => t('Macedonia'), | |
191 'ML' => t('Mali'), | |
192 'MM' => t('Myanmar [Burma]'), | |
193 'MN' => t('Mongolia'), | |
194 'MO' => t('Macau SAR China'), | |
195 'MP' => t('Northern Mariana Islands'), | |
196 'MQ' => t('Martinique'), | |
197 'MR' => t('Mauritania'), | |
198 'MS' => t('Montserrat'), | |
199 'MT' => t('Malta'), | |
200 'MU' => t('Mauritius'), | |
201 'MV' => t('Maldives'), | |
202 'MW' => t('Malawi'), | |
203 'MX' => t('Mexico'), | |
204 'MY' => t('Malaysia'), | |
205 'MZ' => t('Mozambique'), | |
206 'NA' => t('Namibia'), | |
207 'NC' => t('New Caledonia'), | |
208 'NE' => t('Niger'), | |
209 'NF' => t('Norfolk Island'), | |
210 'NG' => t('Nigeria'), | |
211 'NI' => t('Nicaragua'), | |
212 'NL' => t('Netherlands'), | |
213 'NO' => t('Norway'), | |
214 'NP' => t('Nepal'), | |
215 'NR' => t('Nauru'), | |
216 'NU' => t('Niue'), | |
217 'NZ' => t('New Zealand'), | |
218 'OM' => t('Oman'), | |
219 'PA' => t('Panama'), | |
220 'PE' => t('Peru'), | |
221 'PF' => t('French Polynesia'), | |
222 'PG' => t('Papua New Guinea'), | |
223 'PH' => t('Philippines'), | |
224 'PK' => t('Pakistan'), | |
225 'PL' => t('Poland'), | |
226 'PM' => t('Saint Pierre and Miquelon'), | |
227 'PN' => t('Pitcairn Islands'), | |
228 'PR' => t('Puerto Rico'), | |
229 'PS' => t('Palestinian Territories'), | |
230 'PT' => t('Portugal'), | |
231 'PW' => t('Palau'), | |
232 'PY' => t('Paraguay'), | |
233 'QA' => t('Qatar'), | |
234 'QO' => t('Outlying Oceania'), | |
235 'RE' => t('Réunion'), | |
236 'RO' => t('Romania'), | |
237 'RS' => t('Serbia'), | |
238 'RU' => t('Russia'), | |
239 'RW' => t('Rwanda'), | |
240 'SA' => t('Saudi Arabia'), | |
241 'SB' => t('Solomon Islands'), | |
242 'SC' => t('Seychelles'), | |
243 'SD' => t('Sudan'), | |
244 'SE' => t('Sweden'), | |
245 'SG' => t('Singapore'), | |
246 'SH' => t('Saint Helena'), | |
247 'SI' => t('Slovenia'), | |
248 'SJ' => t('Svalbard and Jan Mayen'), | |
249 'SK' => t('Slovakia'), | |
250 'SL' => t('Sierra Leone'), | |
251 'SM' => t('San Marino'), | |
252 'SN' => t('Senegal'), | |
253 'SO' => t('Somalia'), | |
254 'SR' => t('Suriname'), | |
255 'SS' => t('South Sudan'), | |
256 'ST' => t('São Tomé and Príncipe'), | |
257 'SV' => t('El Salvador'), | |
258 'SX' => t('Sint Maarten'), | |
259 'SY' => t('Syria'), | |
260 'SZ' => t('Swaziland'), | |
261 'TA' => t('Tristan da Cunha'), | |
262 'TC' => t('Turks and Caicos Islands'), | |
263 'TD' => t('Chad'), | |
264 'TF' => t('French Southern Territories'), | |
265 'TG' => t('Togo'), | |
266 'TH' => t('Thailand'), | |
267 'TJ' => t('Tajikistan'), | |
268 'TK' => t('Tokelau'), | |
269 'TL' => t('Timor-Leste'), | |
270 'TM' => t('Turkmenistan'), | |
271 'TN' => t('Tunisia'), | |
272 'TO' => t('Tonga'), | |
273 'TR' => t('Turkey'), | |
274 'TT' => t('Trinidad and Tobago'), | |
275 'TV' => t('Tuvalu'), | |
276 'TW' => t('Taiwan'), | |
277 'TZ' => t('Tanzania'), | |
278 'UA' => t('Ukraine'), | |
279 'UG' => t('Uganda'), | |
280 'UM' => t('U.S. Outlying Islands'), | |
281 'US' => t('United States'), | |
282 'UY' => t('Uruguay'), | |
283 'UZ' => t('Uzbekistan'), | |
284 'VA' => t('Vatican City'), | |
285 'VC' => t('Saint Vincent and the Grenadines'), | |
286 'VE' => t('Venezuela'), | |
287 'VG' => t('British Virgin Islands'), | |
288 'VI' => t('U.S. Virgin Islands'), | |
289 'VN' => t('Vietnam'), | |
290 'VU' => t('Vanuatu'), | |
291 'WF' => t('Wallis and Futuna'), | |
292 'WS' => t('Samoa'), | |
293 'XK' => t('Kosovo'), | |
294 'YE' => t('Yemen'), | |
295 'YT' => t('Mayotte'), | |
296 'ZA' => t('South Africa'), | |
297 'ZM' => t('Zambia'), | |
298 'ZW' => t('Zimbabwe'), | |
299 ]; | |
300 | |
301 // Sort the list. | |
302 natcasesort($countries); | |
303 | |
304 return $countries; | |
305 } | |
306 | |
307 /** | |
308 * Get an array of country code => country name pairs, altered by alter hooks. | |
309 * | |
310 * @return array | |
311 * An array of country code => country name pairs. | |
312 * | |
313 * @see \Drupal\Core\Locale\CountryManager::getStandardList() | |
314 */ | |
315 public function getList() { | |
316 // Populate the country list if it is not already populated. | |
317 if (!isset($this->countries)) { | |
318 $this->countries = static::getStandardList(); | |
319 $this->moduleHandler->alter('countries', $this->countries); | |
320 } | |
321 | |
322 return $this->countries; | |
323 } | |
324 | |
325 } |