addressfield.address_formats.inc 21 KB

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