CountryManager.php 9.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php

namespace Drupal\Core\Locale;

use Drupal\Core\Extension\ModuleHandlerInterface;

/**
 * Provides list of countries.
 */
class CountryManager implements CountryManagerInterface {

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * An array of country code => country name pairs.
   */
  protected $countries;

24
  /**
25 26 27 28
   * Constructor.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   */
29 30 31 32 33
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

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

    // Sort the list.
    natcasesort($countries);

    return $countries;
  }

  /**
   * Get an array of country code => country name pairs, altered by alter hooks.
   *
   * @return array
   *   An array of country code => country name pairs.
   *
   * @see \Drupal\Core\Locale\CountryManager::getStandardList()
   */
  public function getList() {
    // Populate the country list if it is not already populated.
    if (!isset($this->countries)) {
      $this->countries = static::getStandardList();
      $this->moduleHandler->alter('countries', $this->countries);
    }

    return $this->countries;
  }

}