123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- <?php
- /**
- * Contains the predefined address formats.
- *
- * Derived from Google's dataset: https://chromium-i18n.appspot.com/ssl-address.
- */
- /**
- * Returns the address format for the given country code.
- *
- * @param $country_code
- * The country code for which the address format should be returned.
- *
- * @return
- * The address format array with the following keys:
- * - used_fields: An array of fields used by this format. Possible values:
- * 'dependent_locality', 'locality', 'administrative_area', 'postal_code'.
- * - required_fields: An array of required fields. See "used_fields".
- * - dependent_locality_label: The label for the dependent locality field.
- * - locality_label: The label for the locality field.
- * - administrative_area_label: The label for the administrative area field.
- * - postal_code_label: The label for the postal code field.
- * - render_administrative_area_value: True if the value should be rendered
- * instead of the ISO code. US example: California instead of CA.
- * Only relevant for countries with predefined administrative areas.
- */
- function addressfield_get_address_format($country_code) {
- $default_values = array(
- 'used_fields' => array('locality'),
- 'required_fields' => array('locality'),
- 'dependent_locality_label' => t('Suburb'),
- 'locality_label' => t('City'),
- 'administrative_area_label' => t('Province'),
- 'postal_code_label' => t('Postal code'),
- 'render_administrative_area_value' => FALSE,
- );
- $address_formats = array();
- // These formats differ from the default only by the presence of the
- // postal code in 'used_fields'.
- $countries_with_optional_postal_code = array(
- 'AC', 'AD', 'AF', 'AI', 'AL', 'AZ', 'BA', 'BB', 'BD', 'BG', 'BH', 'BM',
- 'BN', 'BT', 'CU', 'CR', 'CY', 'DO', 'DZ', 'EC', 'EH', 'ET', 'FO', 'GE',
- 'GN', 'GT', 'GW', 'HR', 'HM', 'HT', 'IL', 'IS', 'JO', 'KE', 'KG', 'KH',
- 'KP', 'KW', 'LA', 'LB', 'LK', 'LR', 'LS', 'MA', 'MC', 'MD', 'ME', 'MG',
- 'MK', 'MM', 'MT', 'MU', 'MV', 'NE', 'NP', 'OM', 'PK', 'PY', 'RO', 'RS',
- 'SA', 'SD', 'SI', 'SN', 'SZ', 'TA', 'TJ', 'TM', 'TN', 'TZ', 'VA', 'VC',
- 'VG', 'XK', 'ZM',
- );
- foreach ($countries_with_optional_postal_code as $code) {
- $address_formats[$code] = array(
- 'used_fields' => array('locality', 'postal_code'),
- );
- }
- // These formats differ from the default only by the presence of the
- // postal code in 'used_fields' and 'required_fields'.
- $countries_with_required_postal_code = array(
- 'AT', 'AX', 'BE', 'BL', 'CH', 'CZ', 'DE', 'DK', 'FI', 'FK', 'FR', 'GF', 'GG',
- 'GL', 'GP', 'GR', 'GS', 'HU', 'IM', 'IO', 'JE', 'LI', 'LU', 'MF', 'MQ', 'NC',
- 'NL', 'NO', 'PL', 'PM', 'PN', 'PT', 'RE', 'SE', 'SH', 'SJ', 'SK', 'TC', 'WF',
- 'YT',
- );
- foreach ($countries_with_required_postal_code as $code) {
- $address_formats[$code] = array(
- 'used_fields' => array('locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- );
- }
- $address_formats['AE'] = array(
- 'used_fields' => array('administrative_area'),
- 'administrative_area_label' => t('Emirate'),
- 'render_administrative_area_value' => TRUE,
- 'required_fields' => array('administrative_area'),
- );
- $address_formats['AM'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['AR'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['AS'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['AU'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'locality_label' => t('City/Suburb'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('Postcode'),
- );
- $address_formats['BR'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'dependent_locality_label' => t('Neighborhood'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['BS'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['BY'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['CA'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['CC'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['CL'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['CN'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'dependent_locality_label' => t('District'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['CO'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['CV'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['CX'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['EG'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Governorate'),
- );
- $address_formats['EE'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'administrative_area_label' => t('County'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['ES'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['FM'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['GB'] = array(
- 'used_fields' => array('locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'locality_label' => t('Town/City'),
- 'administrative_area_label' => t('County'),
- 'postal_code_label' => t('Postcode'),
- );
- $address_formats['GI'] = array(
- 'used_fields' => array('postal_code'),
- );
- $address_formats['GU'] = array(
- 'used_fields' => array('locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['HK'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'required_fields' => array('administrative_area'),
- 'locality_label' => t('District'),
- 'administrative_area_label' => t('Area', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['HN'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['ID'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('administrative_area'),
- 'locality_label' => t('City/Regency'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['IE'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'locality_label' => t('Town/City'),
- 'administrative_area_label' => t('County'),
- 'postal_code_label' => t('Eircode'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['IN'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('PIN code'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['IQ'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['IR'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'dependent_locality_label' => t('Neighborhood'),
- );
- $address_formats['IT'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['JM'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Parish', array(), array('context' => 'Territory of a country')),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['JP'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Prefecture'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['KI'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['KN'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['KR'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'dependent_locality_label' => t('District'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['KY'] = array(
- 'used_fields' => array('administrative_area', 'postal_code'),
- 'required_fields' => array('administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['KZ'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['LT'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'administrative_area_label' => t('County'),
- );
- $address_formats['LV'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'administrative_area_label' => t('Municipality'),
- );
- $address_formats['MH'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['MN'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['MP'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['MX'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'dependent_locality_label' => t('Neighborhood'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['MY'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'dependent_locality_label' => t('Village / Township'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['MZ'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['NF'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['NG'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['NI'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['NR'] = array(
- 'used_fields' => array('administrative_area'),
- 'required_fields' => array('administrative_area'),
- 'administrative_area_label' => t('District'),
- );
- $address_formats['NZ'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'locality_label' => t('Town/City'),
- 'postal_code_label' => t('Postcode'),
- );
- $address_formats['PA'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['PE'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'locality_label' => t('District'),
- 'administrative_area_label' => t('Department', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['PF'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['PG'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['PH'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['PR'] = array(
- 'used_fields' => array('locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['PW'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['RU'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['SC'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['SG'] = array(
- 'used_fields' => array('postal_code'),
- 'required_fields' => array('postal_code'),
- );
- $address_formats['SM'] = array(
- 'used_fields' => array('locality', 'postal_code'),
- 'required_fields' => array('postal_code'),
- );
- $address_formats['SO'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['SR'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['SV'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- );
- $address_formats['TH'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['TR'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- 'locality_label' => t('District'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['TV'] = array(
- 'used_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('Island'),
- );
- $address_formats['TW'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['UA'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('Region', array(), array('context' => 'Territory of a country')),
- );
- $address_formats['UM'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['US'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['UY'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['UZ'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['VE'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area'),
- 'render_administrative_area_value' => TRUE,
- );
- $address_formats['VI'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'required_fields' => array('locality', 'administrative_area', 'postal_code'),
- 'administrative_area_label' => t('State', array(), array('context' => 'Territory of a country')),
- 'postal_code_label' => t('ZIP code'),
- );
- $address_formats['VN'] = array(
- 'used_fields' => array('locality', 'administrative_area', 'postal_code'),
- );
- $address_formats['ZA'] = array(
- 'used_fields' => array('dependent_locality', 'locality', 'postal_code'),
- 'required_fields' => array('locality', 'postal_code'),
- );
- // Allow other modules to alter the formats.
- drupal_alter('addressfield_address_formats', $address_formats);
- if (isset($address_formats[$country_code])) {
- $format = $address_formats[$country_code] + $default_values;
- }
- else {
- // There is no predefined address format for the requested country,
- // but the defaults should work fine.
- $format = $default_values;
- }
- return $format;
- }
|