PageRenderTime 93ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/core/lib/Drupal/Core/Locale/CountryManager.php

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