CountryManager.php 9.2 KB

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