addressfield.address_formats.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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', 'CZ', '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. 'SK', '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', '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', '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('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'),
  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. );
  234. $address_formats['KY'] = array(
  235. 'used_fields' => array('administrative_area', 'postal_code'),
  236. 'required_fields' => array('administrative_area'),
  237. 'administrative_area_label' => t('Island'),
  238. );
  239. $address_formats['KZ'] = array(
  240. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  241. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  242. 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
  243. 'render_administrative_area_value' => TRUE,
  244. );
  245. $address_formats['LT'] = array(
  246. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  247. 'required_fields' => array('locality', 'postal_code'),
  248. 'administrative_area_label' => t('County'),
  249. );
  250. $address_formats['LV'] = array(
  251. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  252. 'required_fields' => array('locality', 'postal_code'),
  253. 'administrative_area_label' => t('Municipality'),
  254. );
  255. $address_formats['MH'] = array(
  256. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  257. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  258. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  259. 'postal_code_label' => t('ZIP code'),
  260. );
  261. $address_formats['MN'] = array(
  262. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  263. );
  264. $address_formats['MP'] = 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['MX'] = array(
  271. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  272. 'required_fields' => array('locality', 'postal_code'),
  273. 'dependent_locality_label' => t('Neighborhood'),
  274. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  275. );
  276. $address_formats['MY'] = array(
  277. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  278. 'required_fields' => array('locality', 'postal_code'),
  279. 'dependent_locality_label' => t('Village / Township'),
  280. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  281. 'render_administrative_area_value' => TRUE,
  282. );
  283. $address_formats['MZ'] = array(
  284. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  285. );
  286. $address_formats['NF'] = array(
  287. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  288. );
  289. $address_formats['NG'] = array(
  290. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  291. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  292. );
  293. $address_formats['NI'] = array(
  294. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  295. 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
  296. );
  297. $address_formats['NR'] = array(
  298. 'used_fields' => array('administrative_area'),
  299. 'required_fields' => array('administrative_area'),
  300. 'administrative_area_label' => t('District'),
  301. );
  302. $address_formats['NZ'] = array(
  303. 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
  304. 'required_fields' => array('locality', 'postal_code'),
  305. 'locality_label' => t('Town/City'),
  306. 'postal_code_label' => t('Postcode'),
  307. );
  308. $address_formats['PA'] = array(
  309. 'used_fields' => array('locality', 'administrative_area'),
  310. );
  311. $address_formats['PE'] = array(
  312. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  313. 'locality_label' => t('District'),
  314. 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
  315. );
  316. $address_formats['PF'] = array(
  317. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  318. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  319. 'administrative_area_label' => t('Island'),
  320. );
  321. $address_formats['PG'] = array(
  322. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  323. 'required_fields' => array('locality', 'administrative_area'),
  324. );
  325. $address_formats['PH'] = array(
  326. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  327. );
  328. $address_formats['PR'] = array(
  329. 'used_fields' => array('locality', 'postal_code'),
  330. 'required_fields' => array('locality', 'postal_code'),
  331. 'postal_code_label' => t('ZIP code'),
  332. );
  333. $address_formats['PW'] = array(
  334. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  335. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  336. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  337. 'postal_code_label' => t('ZIP code'),
  338. );
  339. $address_formats['RU'] = array(
  340. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  341. 'required_fields' => array('locality', 'postal_code'),
  342. 'render_administrative_area_value' => TRUE,
  343. );
  344. $address_formats['SC'] = array(
  345. 'used_fields' => array('locality', 'administrative_area'),
  346. 'administrative_area_label' => t('Island'),
  347. );
  348. $address_formats['SG'] = array(
  349. 'used_fields' => array('postal_code'),
  350. 'required_fields' => array('postal_code'),
  351. );
  352. $address_formats['SM'] = array(
  353. 'used_fields' => array('locality', 'postal_code'),
  354. 'required_fields' => array('postal_code'),
  355. );
  356. $address_formats['SO'] = array(
  357. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  358. 'required_fields' => array('locality', 'administrative_area'),
  359. );
  360. $address_formats['SR'] = array(
  361. 'used_fields' => array('locality', 'administrative_area'),
  362. );
  363. $address_formats['SV'] = array(
  364. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  365. 'required_fields' => array('locality', 'administrative_area'),
  366. );
  367. $address_formats['TH'] = array(
  368. 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
  369. );
  370. $address_formats['TR'] = array(
  371. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  372. 'required_fields' => array('locality', 'postal_code'),
  373. 'locality_label' => t('District'),
  374. 'render_administrative_area_value' => TRUE,
  375. );
  376. $address_formats['TV'] = array(
  377. 'used_fields' => array('locality', 'administrative_area'),
  378. 'administrative_area_label' => t('Island'),
  379. );
  380. $address_formats['TW'] = array(
  381. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  382. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  383. );
  384. $address_formats['UA'] = array(
  385. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  386. 'required_fields' => array('locality', 'postal_code'),
  387. 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
  388. );
  389. $address_formats['UM'] = array(
  390. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  391. 'required_fields' => array('locality', 'administrative_area'),
  392. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  393. 'postal_code_label' => t('ZIP code'),
  394. );
  395. $address_formats['US'] = array(
  396. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  397. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  398. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  399. 'postal_code_label' => t('ZIP code'),
  400. );
  401. $address_formats['UY'] = array(
  402. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  403. );
  404. $address_formats['UZ'] = array(
  405. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  406. );
  407. $address_formats['VE'] = array(
  408. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  409. 'required_fields' => array('locality', 'administrative_area'),
  410. 'render_administrative_area_value' => TRUE,
  411. );
  412. $address_formats['VI'] = array(
  413. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  414. 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
  415. 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
  416. 'postal_code_label' => t('ZIP code'),
  417. );
  418. $address_formats['VN'] = array(
  419. 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
  420. );
  421. $address_formats['ZA'] = array(
  422. 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
  423. 'required_fields' => array('locality', 'postal_code'),
  424. );
  425. // Allow other modules to alter the formats.
  426. drupal_alter('addressfield_address_formats', $address_formats);
  427. if (isset($address_formats[$country_code])) {
  428. $format = $address_formats[$country_code] + $default_values;
  429. }
  430. else {
  431. // There is no predefined address format for the requested country,
  432. // but the defaults should work fine.
  433. $format = $default_values;
  434. }
  435. return $format;
  436. }