addressfield.address_formats.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?php
  2. /**
  3. * Contains the predefined address formats.
  4. *
  5. * Derived from Google's dataset: https://i18napis.appspot.com/address.
  6. */
  7. /**
  8. * Returns the address format for the given country code.
  9. *
  10. * @param $country_code
  11. * The country code for which the address format should be returned.
  12. *
  13. * @return
  14. * The address format array with the following keys:
  15. * - used_fields: An array of fields used by this format. Possible values:
  16. * 'dependent_locality', 'locality', 'administrative_area', 'postal_code'.
  17. * - required_fields: An array of required fields. See "used_fields".
  18. * - dependent_locality_label: The label for the dependent locality field.
  19. * - locality_label: The label for the locality field.
  20. * - administrative_area_label: The label for the administrative area field.
  21. * - postal_code_label: The label for the postal code field.
  22. * - render_administrative_area_value: True if the value should be rendered
  23. * instead of the ISO code. US example: California instead of CA.
  24. * Only relevant for countries with predefined administrative areas.
  25. */
  26. function addressfield_get_address_format($country_code) {
  27. $default_values = array(
  28. 'used_fields' => array('locality'),
  29. 'required_fields' => array('locality'),
  30. 'dependent_locality_label' => t('Suburb'),
  31. 'locality_label' => t('City'),
  32. 'administrative_area_label' => t('Province'),
  33. 'postal_code_label' => t('Postal code'),
  34. 'render_administrative_area_value' => FALSE,
  35. );
  36. $address_formats = array();
  37. // These formats differ from the default only by the presence of the
  38. // postal code in 'used_fields'.
  39. $countries_with_optional_postal_code = array(
  40. 'AC', 'AD', 'AL', 'AZ', 'BA', 'BB', 'BD', 'BG', 'BH', 'BM', 'BN', 'BT',
  41. 'CR', 'CY', 'DO', 'DZ', 'EC', 'EH', 'ET', 'FO', 'GE', 'GN', 'GT',
  42. 'GW', 'HR', 'HT', 'IL', 'IS', 'JO', 'KE', 'KG', 'KH', 'KW', 'LA',
  43. 'LA', 'LB', 'LK', 'LR', 'LS', 'MA', 'MC', 'MD', 'ME', 'MG', 'MK', 'MM',
  44. 'MT', 'MU', 'MV', 'NE', 'NP', 'OM', 'PK', 'PY', 'RO', 'RS', 'SA', 'SI',
  45. 'SN', 'SZ', 'TA', 'TJ', 'TM', 'TN', 'VA', 'VC', 'VG', 'XK', 'ZM',
  46. );
  47. foreach ($countries_with_optional_postal_code as $code) {
  48. $address_formats[$code] = array(
  49. 'used_fields' => array('locality', 'postal_code'),
  50. );
  51. }
  52. // These formats differ from the default only by the presence of the
  53. // postal code in 'used_fields' and 'required_fields'.
  54. $countries_with_required_postal_code = array(
  55. 'AT', 'AX', 'BE', 'BL', 'CH', 'CZ', 'DE', 'DK', 'FI', 'FK', 'FR', 'GF', 'GG',
  56. 'GL', 'GP', 'GR', 'GS', 'HU', 'IM', 'IO', 'JE', 'LI', 'LU', 'MF', 'MQ', 'NC',
  57. 'NL', 'NO', 'PL', 'PM', 'PN', 'PT', 'RE', 'SE', 'SH', 'SJ', 'SK', 'TC', 'WF',
  58. 'YT',
  59. );
  60. foreach ($countries_with_required_postal_code as $code) {
  61. $address_formats[$code] = array(
  62. 'used_fields' => array('locality', 'postal_code'),
  63. 'required_fields' => array('locality', 'postal_code'),
  64. );
  65. }
  66. $address_formats['AE'] = array(
  67. 'used_fields' => array('administrative_area'),
  68. 'administrative_area_label' => t('Emirate'),
  69. );
  70. $address_formats['AM'] = array(
  71. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  72. );
  73. $address_formats['AR'] = array(
  74. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  75. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  76. 'render_administrative_area_value' => TRUE,
  77. );
  78. $address_formats['AS'] = array(
  79. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  80. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  81. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  82. 'postal_code_label' => t('ZIP code'),
  83. );
  84. $address_formats['AU'] = array(
  85. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  86. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  87. 'locality_label' => t('City/Suburb'),
  88. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  89. 'postal_code_label' => t('Postcode'),
  90. );
  91. $address_formats['BR'] = array(
  92. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  93. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  94. 'dependent_locality_label' => t('Neighborhood'),
  95. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  96. );
  97. $address_formats['BS'] = array(
  98. 'used_fields' => array('locality', 'administrative_area'),
  99. 'administrative_area_label' => t('Island'),
  100. );
  101. $address_formats['BY'] = array(
  102. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  103. );
  104. $address_formats['CA'] = array(
  105. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  106. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  107. );
  108. $address_formats['CC'] = array(
  109. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  110. );
  111. $address_formats['CL'] = array(
  112. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  113. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  114. 'render_administrative_area_value' => TRUE,
  115. );
  116. $address_formats['CN'] = array(
  117. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  118. 'required_fields' => array('locality', 'administrative_area'),
  119. 'dependent_locality_label' => t('District'),
  120. );
  121. $address_formats['CO'] = array(
  122. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  123. 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
  124. );
  125. $address_formats['CV'] = array(
  126. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  127. 'administrative_area_label' => t('Island'),
  128. );
  129. $address_formats['CX'] = array(
  130. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  131. );
  132. $address_formats['EG'] = array(
  133. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  134. 'administrative_area_label' => t('Governorate'),
  135. );
  136. $address_formats['EE'] = array(
  137. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  138. 'required_fields' => array('locality', 'postal_code'),
  139. 'administrative_area_label' => t('County'),
  140. );
  141. $address_formats['ES'] = array(
  142. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  143. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  144. 'render_administrative_area_value' => TRUE,
  145. );
  146. $address_formats['FM'] = array(
  147. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  148. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  149. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  150. 'postal_code_label' => t('ZIP code'),
  151. );
  152. $address_formats['GB'] = array(
  153. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  154. 'required_fields' => array('locality', 'postal_code'),
  155. 'locality_label' => t('Town/City'),
  156. 'administrative_area_label' => t('County'),
  157. 'postal_code_label' => t('Postcode'),
  158. );
  159. $address_formats['GI'] = array(
  160. 'used_fields' => array('postal_code'),
  161. );
  162. $address_formats['GU'] = array(
  163. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  164. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  165. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  166. 'postal_code_label' => t('ZIP code'),
  167. );
  168. $address_formats['HK'] = array(
  169. 'used_fields' => array('locality', 'administrative_area'),
  170. 'required_fields' => array('administrative_area'),
  171. 'locality_label' => t('District'),
  172. 'administrative_area_label' => t('Area', array(), array('context' => 'Territory of a country')),
  173. );
  174. $address_formats['HN'] = array(
  175. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  176. 'required_fields' => array('locality', 'administrative_area'),
  177. );
  178. $address_formats['ID'] = array(
  179. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  180. 'locality_label' => t('City/Regency'),
  181. 'render_administrative_area_value' => TRUE,
  182. );
  183. $address_formats['IE'] = array(
  184. 'used_fields' => array('locality', 'administrative_area'),
  185. 'locality_label' => t('Town/City'),
  186. 'administrative_area_label' => t('County'),
  187. 'render_administrative_area_value' => TRUE,
  188. );
  189. $address_formats['IN'] = array(
  190. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  191. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  192. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  193. 'postal_code_label' => t('PIN code'),
  194. 'render_administrative_area_value' => TRUE,
  195. );
  196. $address_formats['IQ'] = array(
  197. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  198. 'required_fields' => array('locality', 'administrative_area'),
  199. );
  200. $address_formats['IR'] = array(
  201. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  202. 'dependent_locality_label' => t('Neighborhood'),
  203. );
  204. $address_formats['IT'] = array(
  205. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  206. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  207. );
  208. $address_formats['JM'] = array(
  209. 'used_fields' => array('locality', 'administrative_area'),
  210. 'required_fields' => array('locality', 'administrative_area'),
  211. 'administrative_area_label' => t('Parish', array(), array('context' => 'Territory of a country')),
  212. 'render_administrative_area_value' => TRUE,
  213. );
  214. $address_formats['JP'] = array(
  215. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  216. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  217. 'administrative_area_label' => t('Prefecture'),
  218. 'render_administrative_area_value' => TRUE,
  219. );
  220. $address_formats['KI'] = array(
  221. 'used_fields' => array('locality', 'administrative_area'),
  222. 'administrative_area_label' => t('Island'),
  223. );
  224. $address_formats['KN'] = array(
  225. 'used_fields' => array('locality', 'administrative_area'),
  226. 'required_fields' => array('locality', 'administrative_area'),
  227. 'administrative_area_label' => t('Island'),
  228. );
  229. $address_formats['KR'] = array(
  230. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  231. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  232. 'dependent_locality_label' => t('District'),
  233. 'render_administrative_area_value' => TRUE,
  234. );
  235. $address_formats['KY'] = array(
  236. 'used_fields' => array('administrative_area', 'postal_code'),
  237. 'required_fields' => array('administrative_area'),
  238. 'administrative_area_label' => t('Island'),
  239. );
  240. $address_formats['KZ'] = array(
  241. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  242. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  243. 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
  244. 'render_administrative_area_value' => TRUE,
  245. );
  246. $address_formats['LT'] = array(
  247. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  248. 'required_fields' => array('locality', 'postal_code'),
  249. 'administrative_area_label' => t('County'),
  250. );
  251. $address_formats['LV'] = array(
  252. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  253. 'required_fields' => array('locality', 'postal_code'),
  254. 'administrative_area_label' => t('Municipality'),
  255. );
  256. $address_formats['MH'] = array(
  257. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  258. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  259. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  260. 'postal_code_label' => t('ZIP code'),
  261. );
  262. $address_formats['MN'] = array(
  263. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  264. );
  265. $address_formats['MP'] = array(
  266. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  267. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  268. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  269. 'postal_code_label' => t('ZIP code'),
  270. );
  271. $address_formats['MX'] = array(
  272. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  273. 'required_fields' => array('locality', 'postal_code'),
  274. 'dependent_locality_label' => t('Neighborhood'),
  275. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  276. );
  277. $address_formats['MY'] = array(
  278. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  279. 'required_fields' => array('locality', 'postal_code'),
  280. 'dependent_locality_label' => t('Village / Township'),
  281. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  282. 'render_administrative_area_value' => TRUE,
  283. );
  284. $address_formats['MZ'] = array(
  285. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  286. );
  287. $address_formats['NF'] = array(
  288. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  289. );
  290. $address_formats['NG'] = array(
  291. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  292. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  293. );
  294. $address_formats['NI'] = array(
  295. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  296. 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
  297. );
  298. $address_formats['NR'] = array(
  299. 'used_fields' => array('administrative_area'),
  300. 'required_fields' => array('administrative_area'),
  301. 'administrative_area_label' => t('District'),
  302. );
  303. $address_formats['NZ'] = array(
  304. 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
  305. 'required_fields' => array('locality', 'postal_code'),
  306. 'locality_label' => t('Town/City'),
  307. 'postal_code_label' => t('Postcode'),
  308. );
  309. $address_formats['PA'] = array(
  310. 'used_fields' => array('locality', 'administrative_area'),
  311. );
  312. $address_formats['PE'] = array(
  313. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  314. 'locality_label' => t('District'),
  315. 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
  316. );
  317. $address_formats['PF'] = array(
  318. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  319. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  320. 'administrative_area_label' => t('Island'),
  321. );
  322. $address_formats['PG'] = array(
  323. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  324. 'required_fields' => array('locality', 'administrative_area'),
  325. );
  326. $address_formats['PH'] = array(
  327. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  328. );
  329. $address_formats['PR'] = array(
  330. 'used_fields' => array('locality', 'postal_code'),
  331. 'required_fields' => array('locality', 'postal_code'),
  332. 'postal_code_label' => t('ZIP code'),
  333. );
  334. $address_formats['PW'] = array(
  335. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  336. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  337. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  338. 'postal_code_label' => t('ZIP code'),
  339. );
  340. $address_formats['RU'] = array(
  341. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  342. 'required_fields' => array('locality', 'postal_code'),
  343. 'render_administrative_area_value' => TRUE,
  344. );
  345. $address_formats['SC'] = array(
  346. 'used_fields' => array('locality', 'administrative_area'),
  347. 'administrative_area_label' => t('Island'),
  348. );
  349. $address_formats['SG'] = array(
  350. 'used_fields' => array('postal_code'),
  351. 'required_fields' => array('postal_code'),
  352. );
  353. $address_formats['SM'] = array(
  354. 'used_fields' => array('locality', 'postal_code'),
  355. 'required_fields' => array('postal_code'),
  356. );
  357. $address_formats['SO'] = array(
  358. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  359. 'required_fields' => array('locality', 'administrative_area'),
  360. );
  361. $address_formats['SR'] = array(
  362. 'used_fields' => array('locality', 'administrative_area'),
  363. );
  364. $address_formats['SV'] = array(
  365. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  366. 'required_fields' => array('locality', 'administrative_area'),
  367. );
  368. $address_formats['TH'] = array(
  369. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  370. );
  371. $address_formats['TR'] = array(
  372. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  373. 'required_fields' => array('locality', 'postal_code'),
  374. 'locality_label' => t('District'),
  375. 'render_administrative_area_value' => TRUE,
  376. );
  377. $address_formats['TV'] = array(
  378. 'used_fields' => array('locality', 'administrative_area'),
  379. 'administrative_area_label' => t('Island'),
  380. );
  381. $address_formats['TW'] = array(
  382. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  383. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  384. );
  385. $address_formats['UA'] = array(
  386. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  387. 'required_fields' => array('locality', 'postal_code'),
  388. 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
  389. );
  390. $address_formats['UM'] = array(
  391. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  392. 'required_fields' => array('locality', 'administrative_area'),
  393. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  394. 'postal_code_label' => t('ZIP code'),
  395. );
  396. $address_formats['US'] = array(
  397. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  398. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  399. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  400. 'postal_code_label' => t('ZIP code'),
  401. );
  402. $address_formats['UY'] = array(
  403. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  404. );
  405. $address_formats['UZ'] = array(
  406. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  407. );
  408. $address_formats['VE'] = array(
  409. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  410. 'required_fields' => array('locality', 'administrative_area'),
  411. 'render_administrative_area_value' => TRUE,
  412. );
  413. $address_formats['VI'] = array(
  414. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  415. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  416. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  417. 'postal_code_label' => t('ZIP code'),
  418. );
  419. $address_formats['VN'] = array(
  420. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  421. );
  422. $address_formats['ZA'] = array(
  423. 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
  424. 'required_fields' => array('locality', 'postal_code'),
  425. );
  426. // Allow other modules to alter the formats.
  427. drupal_alter('addressfield_address_formats', $address_formats);
  428. if (isset($address_formats[$country_code])) {
  429. $format = $address_formats[$country_code] + $default_values;
  430. }
  431. else {
  432. // There is no predefined address format for the requested country,
  433. // but the defaults should work fine.
  434. $format = $default_values;
  435. }
  436. return $format;
  437. }