summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries2013-06-28 17:05:50 (GMT)
committerDries2013-06-28 17:06:49 (GMT)
commit6f29144a10f863b203a562f534605dab6055c4a0 (patch)
tree9f45cf94a6b369423ed20d5dc3679d421c6f7e80
parent2a993a893b7b882d8677a1ac3e983d2fa6c73335 (diff)
Issue #1938892 by JohnAlbin, Pancho: Fixed Switch from ISO-3166-1 country data to CLDR unicode data.
-rw-r--r--core/lib/Drupal/Core/Locale/CountryManager.php78
-rw-r--r--core/modules/system/system.api.php2
-rwxr-xr-xcore/scripts/update-countries.sh99
-rw-r--r--core/scripts/update-iso-3166.sh72
4 files changed, 143 insertions, 108 deletions
diff --git a/core/lib/Drupal/Core/Locale/CountryManager.php b/core/lib/Drupal/Core/Locale/CountryManager.php
index 33a0a55..6617459 100644
--- a/core/lib/Drupal/Core/Locale/CountryManager.php
+++ b/core/lib/Drupal/Core/Locale/CountryManager.php
@@ -36,13 +36,14 @@ class CountryManager implements CountryManagerInterface {
}
/**
- * Get an array of all ISO 3166-1 alpha-2 country code => country name pairs.
+ * Get an array of all two-letter country code => country name pairs.
*
* @return array
* An array of country code => country name pairs.
*/
public static function getStandardList() {
$countries = array(
+ 'AC' => t('Ascension Island'),
'AD' => t('Andorra'),
'AE' => t('United Arab Emirates'),
'AF' => t('Afghanistan'),
@@ -71,9 +72,9 @@ class CountryManager implements CountryManagerInterface {
'BJ' => t('Benin'),
'BL' => t('Saint Barthélemy'),
'BM' => t('Bermuda'),
- 'BN' => t('Brunei Darussalam'),
- 'BO' => t('Bolivia, Plurinational State of'),
- 'BQ' => t('Bonaire, Sint Eustatius and Saba'),
+ 'BN' => t('Brunei'),
+ 'BO' => t('Bolivia'),
+ 'BQ' => t('Caribbean Netherlands'),
'BR' => t('Brazil'),
'BS' => t('Bahamas'),
'BT' => t('Bhutan'),
@@ -82,17 +83,18 @@ class CountryManager implements CountryManagerInterface {
'BY' => t('Belarus'),
'BZ' => t('Belize'),
'CA' => t('Canada'),
- 'CC' => t('Cocos (Keeling) Islands'),
- 'CD' => t('Congo, The Democratic Republic of the'),
+ 'CC' => t('Cocos [Keeling] Islands'),
+ 'CD' => t('Congo - Kinshasa'),
'CF' => t('Central African Republic'),
- 'CG' => t('Congo'),
+ 'CG' => t('Congo - Brazzaville'),
'CH' => t('Switzerland'),
- 'CI' => t("Côte d'Ivoire"),
+ 'CI' => t('Côte d’Ivoire'),
'CK' => t('Cook Islands'),
'CL' => t('Chile'),
'CM' => t('Cameroon'),
'CN' => t('China'),
'CO' => t('Colombia'),
+ 'CP' => t('Clipperton Island'),
'CR' => t('Costa Rica'),
'CU' => t('Cuba'),
'CV' => t('Cape Verde'),
@@ -101,11 +103,13 @@ class CountryManager implements CountryManagerInterface {
'CY' => t('Cyprus'),
'CZ' => t('Czech Republic'),
'DE' => t('Germany'),
+ 'DG' => t('Diego Garcia'),
'DJ' => t('Djibouti'),
'DK' => t('Denmark'),
'DM' => t('Dominica'),
'DO' => t('Dominican Republic'),
'DZ' => t('Algeria'),
+ 'EA' => t('Ceuta and Melilla'),
'EC' => t('Ecuador'),
'EE' => t('Estonia'),
'EG' => t('Egypt'),
@@ -115,8 +119,8 @@ class CountryManager implements CountryManagerInterface {
'ET' => t('Ethiopia'),
'FI' => t('Finland'),
'FJ' => t('Fiji'),
- 'FK' => t('Falkland Islands (Malvinas)'),
- 'FM' => t('Micronesia, Federated States of'),
+ 'FK' => t('Falkland Islands'),
+ 'FM' => t('Micronesia'),
'FO' => t('Faroe Islands'),
'FR' => t('France'),
'GA' => t('Gabon'),
@@ -138,12 +142,13 @@ class CountryManager implements CountryManagerInterface {
'GU' => t('Guam'),
'GW' => t('Guinea-Bissau'),
'GY' => t('Guyana'),
- 'HK' => t('Hong Kong'),
+ 'HK' => t('Hong Kong SAR China'),
'HM' => t('Heard Island and McDonald Islands'),
'HN' => t('Honduras'),
'HR' => t('Croatia'),
'HT' => t('Haiti'),
'HU' => t('Hungary'),
+ 'IC' => t('Canary Islands'),
'ID' => t('Indonesia'),
'IE' => t('Ireland'),
'IL' => t('Israel'),
@@ -151,7 +156,7 @@ class CountryManager implements CountryManagerInterface {
'IN' => t('India'),
'IO' => t('British Indian Ocean Territory'),
'IQ' => t('Iraq'),
- 'IR' => t('Iran, Islamic Republic of'),
+ 'IR' => t('Iran'),
'IS' => t('Iceland'),
'IT' => t('Italy'),
'JE' => t('Jersey'),
@@ -164,12 +169,12 @@ class CountryManager implements CountryManagerInterface {
'KI' => t('Kiribati'),
'KM' => t('Comoros'),
'KN' => t('Saint Kitts and Nevis'),
- 'KP' => t("Korea, Democratic People's Republic of"),
- 'KR' => t('Korea, Republic of'),
+ 'KP' => t('North Korea'),
+ 'KR' => t('South Korea'),
'KW' => t('Kuwait'),
'KY' => t('Cayman Islands'),
'KZ' => t('Kazakhstan'),
- 'LA' => t("Lao People's Democratic Republic"),
+ 'LA' => t('Laos'),
'LB' => t('Lebanon'),
'LC' => t('Saint Lucia'),
'LI' => t('Liechtenstein'),
@@ -182,16 +187,16 @@ class CountryManager implements CountryManagerInterface {
'LY' => t('Libya'),
'MA' => t('Morocco'),
'MC' => t('Monaco'),
- 'MD' => t('Moldova, Republic of'),
+ 'MD' => t('Moldova'),
'ME' => t('Montenegro'),
- 'MF' => t('Saint Martin (French part)'),
+ 'MF' => t('Saint Martin'),
'MG' => t('Madagascar'),
'MH' => t('Marshall Islands'),
- 'MK' => t('Macedonia, Republic of'),
+ 'MK' => t('Macedonia'),
'ML' => t('Mali'),
- 'MM' => t('Myanmar'),
+ 'MM' => t('Myanmar [Burma]'),
'MN' => t('Mongolia'),
- 'MO' => t('Macao'),
+ 'MO' => t('Macau SAR China'),
'MP' => t('Northern Mariana Islands'),
'MQ' => t('Martinique'),
'MR' => t('Mauritania'),
@@ -224,17 +229,18 @@ class CountryManager implements CountryManagerInterface {
'PK' => t('Pakistan'),
'PL' => t('Poland'),
'PM' => t('Saint Pierre and Miquelon'),
- 'PN' => t('Pitcairn'),
+ 'PN' => t('Pitcairn Islands'),
'PR' => t('Puerto Rico'),
- 'PS' => t('Palestine, State of'),
+ 'PS' => t('Palestinian Territories'),
'PT' => t('Portugal'),
'PW' => t('Palau'),
'PY' => t('Paraguay'),
'QA' => t('Qatar'),
+ 'QO' => t('Outlying Oceania'),
'RE' => t('Réunion'),
'RO' => t('Romania'),
'RS' => t('Serbia'),
- 'RU' => t('Russian Federation'),
+ 'RU' => t('Russia'),
'RW' => t('Rwanda'),
'SA' => t('Saudi Arabia'),
'SB' => t('Solomon Islands'),
@@ -242,7 +248,7 @@ class CountryManager implements CountryManagerInterface {
'SD' => t('Sudan'),
'SE' => t('Sweden'),
'SG' => t('Singapore'),
- 'SH' => t('Saint Helena, Ascension and Tristan da Cunha'),
+ 'SH' => t('Saint Helena'),
'SI' => t('Slovenia'),
'SJ' => t('Svalbard and Jan Mayen'),
'SK' => t('Slovakia'),
@@ -252,11 +258,12 @@ class CountryManager implements CountryManagerInterface {
'SO' => t('Somalia'),
'SR' => t('Suriname'),
'SS' => t('South Sudan'),
- 'ST' => t('Sao Tome and Principe'),
+ 'ST' => t('São Tomé and Príncipe'),
'SV' => t('El Salvador'),
- 'SX' => t('Sint Maarten (Dutch part)'),
- 'SY' => t('Syrian Arab Republic'),
+ 'SX' => t('Sint Maarten'),
+ 'SY' => t('Syria'),
'SZ' => t('Swaziland'),
+ 'TA' => t('Tristan da Cunha'),
'TC' => t('Turks and Caicos Islands'),
'TD' => t('Chad'),
'TF' => t('French Southern Territories'),
@@ -271,23 +278,24 @@ class CountryManager implements CountryManagerInterface {
'TR' => t('Turkey'),
'TT' => t('Trinidad and Tobago'),
'TV' => t('Tuvalu'),
- 'TW' => t('Taiwan, Province of China'),
- 'TZ' => t('Tanzania, United Republic of'),
+ 'TW' => t('Taiwan'),
+ 'TZ' => t('Tanzania'),
'UA' => t('Ukraine'),
'UG' => t('Uganda'),
- 'UM' => t('United States Minor Outlying Islands'),
+ 'UM' => t('U.S. Outlying Islands'),
'US' => t('United States'),
'UY' => t('Uruguay'),
'UZ' => t('Uzbekistan'),
- 'VA' => t('Holy See (Vatican City State)'),
+ 'VA' => t('Vatican City'),
'VC' => t('Saint Vincent and the Grenadines'),
- 'VE' => t('Venezuela, Bolivarian Republic of'),
- 'VG' => t('Virgin Islands, British'),
- 'VI' => t('Virgin Islands, U.S.'),
- 'VN' => t('Viet Nam'),
+ 'VE' => t('Venezuela'),
+ 'VG' => t('British Virgin Islands'),
+ 'VI' => t('U.S. Virgin Islands'),
+ 'VN' => t('Vietnam'),
'VU' => t('Vanuatu'),
'WF' => t('Wallis and Futuna'),
'WS' => t('Samoa'),
+ 'XK' => t('Kosovo'),
'YE' => t('Yemen'),
'YT' => t('Mayotte'),
'ZA' => t('South Africa'),
diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php
index 16bb0de..6321a6c 100644
--- a/core/modules/system/system.api.php
+++ b/core/modules/system/system.api.php
@@ -3468,7 +3468,7 @@ function hook_updater_info_alter(&$updaters) {
* Alter the default country list.
*
* @param $countries
- * The associative array of countries keyed by ISO 3166-1 country code.
+ * The associative array of countries keyed by two-letter country code.
*
* @see \Drupal\Core\Locale\CountryManager::getList().
*/
diff --git a/core/scripts/update-countries.sh b/core/scripts/update-countries.sh
new file mode 100755
index 0000000..eee5fa2
--- /dev/null
+++ b/core/scripts/update-countries.sh
@@ -0,0 +1,99 @@
+#!/bin/php
+<?php
+
+/**
+ * @file
+ * Updates CLDR codes in CountryManager.php to latest data.
+ *
+ * We rely on the CLDR data set, because it is easily accessible, scriptable,
+ * and in the right human-readable format.
+ */
+
+// Determine DRUPAL_ROOT.
+$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 = DRUPAL_ROOT . '/territories.json';
+
+if (!file_exists($uri)) {
+ $usage = <<< USAGE
+- Choose the latest release data from http://cldr.unicode.org/index/downloads
+ and download the json.zip file.
+- Unzip the json.zip file and place the main/en/territories.json in the
+ Drupal root directory.
+- Run this script.
+USAGE;
+ exit('CLDR data file not found. (' . $uri . ")\n\n" . $usage . "\n");
+}
+
+// Fake the t() function used in CountryManager.php instead of attempting a full
+// Drupal bootstrap of core/includes/bootstrap.inc (where t() is declared).
+if (!function_exists('t')) {
+ function t($string) {
+ return $string;
+ }
+}
+
+// Read in existing codes.
+// @todo Allow to remove previously existing country codes.
+// @see http://drupal.org/node/1436754
+require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManagerInterface.php';
+require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
+$existing_countries = \Drupal\Core\Locale\CountryManager::getStandardList();
+$countries = $existing_countries;
+
+// Parse the source data into an array.
+$data = json_decode(file_get_contents($uri));
+
+foreach ($data->main->en->localeDisplayNames->territories as $code => $name) {
+ // Use any alternate codes the Drupal community wishes to.
+ $alt_codes = array(
+ // 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry.
+ );
+ if (in_array($code, $alt_codes)) {
+ // Just use the first 2 character part of the alt code.
+ $code = strtok($code, '-');
+ }
+
+ // Skip any codes we wish to exclude from our country list.
+ $exclude_codes = array(
+ 'EU', // The European Union is not a country.
+ 'ZZ', // Don't allow "Unknown Region".
+ );
+ if (in_array($code, $exclude_codes)) {
+ continue;
+ }
+
+ // Ignore every territory that doesn't have a 2 character code.
+ if (strlen($code) !== 2) {
+ continue;
+ }
+ $countries[(string) $code] = $name;
+}
+if (empty($countries)) {
+ echo 'ERROR: Did not find expected 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/lib/Drupal/Core/Locale/CountryManager.php';
+$content = file_get_contents($file);
+$content = preg_replace('/(\$countries = array\(\n)(.+?)(^\s+\);)/ms', '$1' . $out . '$3', $content);
+file_put_contents($file, $content);
diff --git a/core/scripts/update-iso-3166.sh b/core/scripts/update-iso-3166.sh
deleted file mode 100644
index e06f059..0000000
--- a/core/scripts/update-iso-3166.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/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/lib/Drupal/Core/Locale/CountryManagerInterface.php';
-require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
-$existing_countries = \Drupal\Core\Locale\CountryManager::getStandardList();
-$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);