Issue #1068840 by sun, TR, Alan D., droplet, Damien Tournoud, tim.plunkett: Fixed core/includes/standard.inc contains inaccurate country data.

8.0.x
webchick 2013-02-27 21:56:54 -05:00
parent 6dd3740f0e
commit bc70abb3c6
2 changed files with 113 additions and 29 deletions

View File

@ -39,7 +39,7 @@ function standard_country_list() {
'AT' => $t('Austria'), 'AT' => $t('Austria'),
'AU' => $t('Australia'), 'AU' => $t('Australia'),
'AW' => $t('Aruba'), 'AW' => $t('Aruba'),
'AX' => $t('Aland Islands'), 'AX' => $t('Åland Islands'),
'AZ' => $t('Azerbaijan'), 'AZ' => $t('Azerbaijan'),
'BA' => $t('Bosnia and Herzegovina'), 'BA' => $t('Bosnia and Herzegovina'),
'BB' => $t('Barbados'), 'BB' => $t('Barbados'),
@ -52,8 +52,9 @@ function standard_country_list() {
'BJ' => $t('Benin'), 'BJ' => $t('Benin'),
'BL' => $t('Saint Barthélemy'), 'BL' => $t('Saint Barthélemy'),
'BM' => $t('Bermuda'), 'BM' => $t('Bermuda'),
'BN' => $t('Brunei'), 'BN' => $t('Brunei Darussalam'),
'BO' => $t('Bolivia'), 'BO' => $t('Bolivia, Plurinational State of'),
'BQ' => $t('Bonaire, Sint Eustatius and Saba'),
'BR' => $t('Brazil'), 'BR' => $t('Brazil'),
'BS' => $t('Bahamas'), 'BS' => $t('Bahamas'),
'BT' => $t('Bhutan'), 'BT' => $t('Bhutan'),
@ -63,11 +64,11 @@ function standard_country_list() {
'BZ' => $t('Belize'), 'BZ' => $t('Belize'),
'CA' => $t('Canada'), 'CA' => $t('Canada'),
'CC' => $t('Cocos (Keeling) Islands'), 'CC' => $t('Cocos (Keeling) Islands'),
'CD' => $t('Congo (Kinshasa)'), 'CD' => $t('Congo, The Democratic Republic of the'),
'CF' => $t('Central African Republic'), 'CF' => $t('Central African Republic'),
'CG' => $t('Congo (Brazzaville)'), 'CG' => $t('Congo'),
'CH' => $t('Switzerland'), 'CH' => $t('Switzerland'),
'CI' => $t('Ivory Coast'), 'CI' => $t("Côte d'Ivoire"),
'CK' => $t('Cook Islands'), 'CK' => $t('Cook Islands'),
'CL' => $t('Chile'), 'CL' => $t('Chile'),
'CM' => $t('Cameroon'), 'CM' => $t('Cameroon'),
@ -75,8 +76,8 @@ function standard_country_list() {
'CO' => $t('Colombia'), 'CO' => $t('Colombia'),
'CR' => $t('Costa Rica'), 'CR' => $t('Costa Rica'),
'CU' => $t('Cuba'), 'CU' => $t('Cuba'),
'CW' => $t('Curaçao'),
'CV' => $t('Cape Verde'), 'CV' => $t('Cape Verde'),
'CW' => $t('Curaçao'),
'CX' => $t('Christmas Island'), 'CX' => $t('Christmas Island'),
'CY' => $t('Cyprus'), 'CY' => $t('Cyprus'),
'CZ' => $t('Czech Republic'), 'CZ' => $t('Czech Republic'),
@ -95,8 +96,8 @@ function standard_country_list() {
'ET' => $t('Ethiopia'), 'ET' => $t('Ethiopia'),
'FI' => $t('Finland'), 'FI' => $t('Finland'),
'FJ' => $t('Fiji'), 'FJ' => $t('Fiji'),
'FK' => $t('Falkland Islands'), 'FK' => $t('Falkland Islands (Malvinas)'),
'FM' => $t('Micronesia'), 'FM' => $t('Micronesia, Federated States of'),
'FO' => $t('Faroe Islands'), 'FO' => $t('Faroe Islands'),
'FR' => $t('France'), 'FR' => $t('France'),
'GA' => $t('Gabon'), 'GA' => $t('Gabon'),
@ -118,7 +119,7 @@ function standard_country_list() {
'GU' => $t('Guam'), 'GU' => $t('Guam'),
'GW' => $t('Guinea-Bissau'), 'GW' => $t('Guinea-Bissau'),
'GY' => $t('Guyana'), 'GY' => $t('Guyana'),
'HK' => $t('Hong Kong S.A.R., China'), 'HK' => $t('Hong Kong'),
'HM' => $t('Heard Island and McDonald Islands'), 'HM' => $t('Heard Island and McDonald Islands'),
'HN' => $t('Honduras'), 'HN' => $t('Honduras'),
'HR' => $t('Croatia'), 'HR' => $t('Croatia'),
@ -131,7 +132,7 @@ function standard_country_list() {
'IN' => $t('India'), 'IN' => $t('India'),
'IO' => $t('British Indian Ocean Territory'), 'IO' => $t('British Indian Ocean Territory'),
'IQ' => $t('Iraq'), 'IQ' => $t('Iraq'),
'IR' => $t('Iran'), 'IR' => $t('Iran, Islamic Republic of'),
'IS' => $t('Iceland'), 'IS' => $t('Iceland'),
'IT' => $t('Italy'), 'IT' => $t('Italy'),
'JE' => $t('Jersey'), 'JE' => $t('Jersey'),
@ -144,12 +145,12 @@ function standard_country_list() {
'KI' => $t('Kiribati'), 'KI' => $t('Kiribati'),
'KM' => $t('Comoros'), 'KM' => $t('Comoros'),
'KN' => $t('Saint Kitts and Nevis'), 'KN' => $t('Saint Kitts and Nevis'),
'KP' => $t('North Korea'), 'KP' => $t("Korea, Democratic People's Republic of"),
'KR' => $t('South Korea'), 'KR' => $t('Korea, Republic of'),
'KW' => $t('Kuwait'), 'KW' => $t('Kuwait'),
'KY' => $t('Cayman Islands'), 'KY' => $t('Cayman Islands'),
'KZ' => $t('Kazakhstan'), 'KZ' => $t('Kazakhstan'),
'LA' => $t('Laos'), 'LA' => $t("Lao People's Democratic Republic"),
'LB' => $t('Lebanon'), 'LB' => $t('Lebanon'),
'LC' => $t('Saint Lucia'), 'LC' => $t('Saint Lucia'),
'LI' => $t('Liechtenstein'), 'LI' => $t('Liechtenstein'),
@ -162,16 +163,16 @@ function standard_country_list() {
'LY' => $t('Libya'), 'LY' => $t('Libya'),
'MA' => $t('Morocco'), 'MA' => $t('Morocco'),
'MC' => $t('Monaco'), 'MC' => $t('Monaco'),
'MD' => $t('Moldova'), 'MD' => $t('Moldova, Republic of'),
'ME' => $t('Montenegro'), 'ME' => $t('Montenegro'),
'MF' => $t('Saint Martin (French part)'), 'MF' => $t('Saint Martin (French part)'),
'MG' => $t('Madagascar'), 'MG' => $t('Madagascar'),
'MH' => $t('Marshall Islands'), 'MH' => $t('Marshall Islands'),
'MK' => $t('Macedonia'), 'MK' => $t('Macedonia, Republic of'),
'ML' => $t('Mali'), 'ML' => $t('Mali'),
'MM' => $t('Myanmar'), 'MM' => $t('Myanmar'),
'MN' => $t('Mongolia'), 'MN' => $t('Mongolia'),
'MO' => $t('Macao S.A.R., China'), 'MO' => $t('Macao'),
'MP' => $t('Northern Mariana Islands'), 'MP' => $t('Northern Mariana Islands'),
'MQ' => $t('Martinique'), 'MQ' => $t('Martinique'),
'MR' => $t('Mauritania'), 'MR' => $t('Mauritania'),
@ -206,15 +207,15 @@ function standard_country_list() {
'PM' => $t('Saint Pierre and Miquelon'), 'PM' => $t('Saint Pierre and Miquelon'),
'PN' => $t('Pitcairn'), 'PN' => $t('Pitcairn'),
'PR' => $t('Puerto Rico'), 'PR' => $t('Puerto Rico'),
'PS' => $t('Palestinian Territory'), 'PS' => $t('Palestine, State of'),
'PT' => $t('Portugal'), 'PT' => $t('Portugal'),
'PW' => $t('Palau'), 'PW' => $t('Palau'),
'PY' => $t('Paraguay'), 'PY' => $t('Paraguay'),
'QA' => $t('Qatar'), 'QA' => $t('Qatar'),
'RE' => $t('Reunion'), 'RE' => $t('Réunion'),
'RO' => $t('Romania'), 'RO' => $t('Romania'),
'RS' => $t('Serbia'), 'RS' => $t('Serbia'),
'RU' => $t('Russia'), 'RU' => $t('Russian Federation'),
'RW' => $t('Rwanda'), 'RW' => $t('Rwanda'),
'SA' => $t('Saudi Arabia'), 'SA' => $t('Saudi Arabia'),
'SB' => $t('Solomon Islands'), 'SB' => $t('Solomon Islands'),
@ -222,7 +223,7 @@ function standard_country_list() {
'SD' => $t('Sudan'), 'SD' => $t('Sudan'),
'SE' => $t('Sweden'), 'SE' => $t('Sweden'),
'SG' => $t('Singapore'), 'SG' => $t('Singapore'),
'SH' => $t('Saint Helena'), 'SH' => $t('Saint Helena, Ascension and Tristan da Cunha'),
'SI' => $t('Slovenia'), 'SI' => $t('Slovenia'),
'SJ' => $t('Svalbard and Jan Mayen'), 'SJ' => $t('Svalbard and Jan Mayen'),
'SK' => $t('Slovakia'), 'SK' => $t('Slovakia'),
@ -231,9 +232,11 @@ function standard_country_list() {
'SN' => $t('Senegal'), 'SN' => $t('Senegal'),
'SO' => $t('Somalia'), 'SO' => $t('Somalia'),
'SR' => $t('Suriname'), 'SR' => $t('Suriname'),
'SS' => $t('South Sudan'),
'ST' => $t('Sao Tome and Principe'), 'ST' => $t('Sao Tome and Principe'),
'SV' => $t('El Salvador'), 'SV' => $t('El Salvador'),
'SY' => $t('Syria'), 'SX' => $t('Sint Maarten (Dutch part)'),
'SY' => $t('Syrian Arab Republic'),
'SZ' => $t('Swaziland'), 'SZ' => $t('Swaziland'),
'TC' => $t('Turks and Caicos Islands'), 'TC' => $t('Turks and Caicos Islands'),
'TD' => $t('Chad'), 'TD' => $t('Chad'),
@ -249,20 +252,20 @@ function standard_country_list() {
'TR' => $t('Turkey'), 'TR' => $t('Turkey'),
'TT' => $t('Trinidad and Tobago'), 'TT' => $t('Trinidad and Tobago'),
'TV' => $t('Tuvalu'), 'TV' => $t('Tuvalu'),
'TW' => $t('Taiwan'), 'TW' => $t('Taiwan, Province of China'),
'TZ' => $t('Tanzania'), 'TZ' => $t('Tanzania, United Republic of'),
'UA' => $t('Ukraine'), 'UA' => $t('Ukraine'),
'UG' => $t('Uganda'), 'UG' => $t('Uganda'),
'UM' => $t('United States Minor Outlying Islands'), 'UM' => $t('United States Minor Outlying Islands'),
'US' => $t('United States'), 'US' => $t('United States'),
'UY' => $t('Uruguay'), 'UY' => $t('Uruguay'),
'UZ' => $t('Uzbekistan'), 'UZ' => $t('Uzbekistan'),
'VA' => $t('Vatican'), 'VA' => $t('Holy See (Vatican City State)'),
'VC' => $t('Saint Vincent and the Grenadines'), 'VC' => $t('Saint Vincent and the Grenadines'),
'VE' => $t('Venezuela'), 'VE' => $t('Venezuela, Bolivarian Republic of'),
'VG' => $t('British Virgin Islands'), 'VG' => $t('Virgin Islands, British'),
'VI' => $t('U.S. Virgin Islands'), 'VI' => $t('Virgin Islands, U.S.'),
'VN' => $t('Vietnam'), 'VN' => $t('Viet Nam'),
'VU' => $t('Vanuatu'), 'VU' => $t('Vanuatu'),
'WF' => $t('Wallis and Futuna'), 'WF' => $t('Wallis and Futuna'),
'WS' => $t('Samoa'), 'WS' => $t('Samoa'),

View File

@ -0,0 +1,81 @@
#!/bin/php
<?php
/**
* @file
* Updates ISO-3166 codes in standard.inc to latest data.
*
* We rely on the Debian ISO code repository, because it is easily accessible,
* scriptable, in the right human-readable format, and all changes went through
* sufficient FOSS community discussion already.
*/
// Determine DRUPAL_ROOT.
$cwd = $dir = dirname(__FILE__);
while (!defined('DRUPAL_ROOT')) {
if (is_dir($dir . '/core')) {
define('DRUPAL_ROOT', $dir);
}
$dir = dirname($dir);
}
// Determine source data file URI to process.
$uri = $cwd . '/iso_3166.xml';
// Despite its actual file name, at least Firefox merges and converts the path
// and filename into a combined filename.
if (!file_exists($uri)) {
$uri = $cwd . '/iso_3166_iso_3166.xml';
}
// Fall back and default to original Debian source.
if (!file_exists($uri)) {
$uri = 'http://anonscm.debian.org/gitweb/?p=iso-codes/iso-codes.git;a=blob_plain;f=iso_3166/iso_3166.xml;hb=master';
}
// Read in existing codes.
// @todo Allow to remove previously existing country codes.
// @see http://drupal.org/node/1436754
require_once DRUPAL_ROOT . '/core/includes/standard.inc';
$existing_countries = standard_country_list();
$countries = $existing_countries;
// Parse the source data into an array.
$data = simplexml_load_file($uri);
foreach ($data->iso_3166_entry as $entry) {
// Ignore every territory that doesn't have a alpha-2 code.
if (!isset($entry['alpha_2_code'])) {
continue;
}
$name = isset($entry['name']) ? (string) $entry['name'] : (string) $entry['official_name'];
$countries[(string) $entry['alpha_2_code']] = $name;
}
if (empty($countries)) {
echo 'ERROR: Did not find expected alpha_2_code country names.' . PHP_EOL;
exit;
}
// Sort by country code (to minimize diffs).
ksort($countries);
// Produce PHP code.
$out = '';
foreach ($countries as $code => $name) {
// For .po translation file's sake, use double-quotes instead of escaped
// single-quotes.
$name = (strpos($name, '\'') !== FALSE ? '"' . $name . '"' : "'" . $name . "'");
$out .= ' ' . var_export($code, TRUE) . ' => $t(' . $name . '),' . "\n";
}
// Replace the actual PHP code in standard.inc.
$file = DRUPAL_ROOT . '/core/includes/standard.inc';
$content = file_get_contents($file);
$content = preg_replace('/(\$countries = array\(\n)(.+?)(^\s+\);)/ms', '$1' . $out . '$3', $content);
file_put_contents($file, $content);
/**
* No-op script helper.
*/
function get_t() {
return function ($string) {
return $string;
};
}