addressfield.address_formats.inc 20 KB

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