Skip to content

Commit

Permalink
Update the dataset from the new endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
bojanz committed Dec 28, 2017
1 parent b1f526c commit 6d05301
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
10 changes: 0 additions & 10 deletions resources/library_customizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ function get_address_format_customizations($countryCode) {
$formatCustomizations['DE'] = [
'format' => '%organization\n%givenName %familyName\n%addressLine1\n%addressLine2\n%postalCode %locality',
];
// Remove the administrative area.
// https://github.com/googlei18n/libaddressinput/issues/115
$formatCustomizations['GU'] = [
'format' => '%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality %postalCode',
'required_fields' => [
'addressLine1',
'locality',
'postalCode',
],
];
// Make the postal codes required, add administrative area fields (EE, LT).
// https://github.com/googlei18n/libaddressinput/issues/64
$formatCustomizations['EE'] = [
Expand Down
10 changes: 5 additions & 5 deletions resources/subdivision/ES.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"country_code": "ES",
"subdivisions": {
"A Coruña": {
"iso_code": "ES-C",
"postal_code_pattern": "15"
},
"Álava": {
"iso_code": "ES-VI",
"postal_code_pattern": "01"
Expand Down Expand Up @@ -106,6 +102,10 @@
"iso_code": "ES-J",
"postal_code_pattern": "23"
},
"La Coruña": {
"iso_code": "ES-C",
"postal_code_pattern": "15"
},
"La Rioja": {
"iso_code": "ES-LO",
"postal_code_pattern": "26"
Expand All @@ -118,7 +118,7 @@
"iso_code": "ES-LE",
"postal_code_pattern": "24"
},
"Lleida": {
"Lérida": {
"iso_code": "ES-L",
"postal_code_pattern": "25"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"Yangcheon-gu": {
"local_code": "양천구",
"postal_code_pattern": "0(?:78|8[01])"
"postal_code_pattern": "0(?:7[89]|8[01])"
},
"Yeongdeungpo-gu": {
"local_code": "영등포구",
Expand Down
2 changes: 1 addition & 1 deletion resources/subdivision/VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"local_code": "Nghệ An",
"iso_code": "VN-22"
},
"Nanh Binh Province": {
"Ninh Binh Province": {
"local_code": "Ninh Bình",
"iso_code": "VN-18"
},
Expand Down
17 changes: 9 additions & 8 deletions scripts/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$countryRepository = new CountryRepository();
$countries = $countryRepository->getList();
ksort($countries);
$serviceUrl = 'http://i18napis.appspot.com/address';
$serviceUrl = 'https://chromium-i18n.appspot.com/ssl-address';

echo "Generating the url list.\n";

Expand All @@ -50,7 +50,7 @@
$foundCountries = ['ZZ'];
$index = file_get_contents($serviceUrl);
foreach ($countries as $countryCode => $countryName) {
$link = "<a href='/address/data/{$countryCode}'>";
$link = "<a href='/ssl-address/data/{$countryCode}'>";
// This is still faster than running a file_exists() for each country code.
if (strpos($index, $link) !== false) {
$foundCountries[] = $countryCode;
Expand All @@ -77,11 +77,12 @@
}
$addressFormat = create_address_format_definition($countryCode, $definition);

// Create a list of available translations.
// Ignore Hong Kong because the listed translation (English) is already
// provided through the lname property.
// Get the French subdivision names for Canada.
// This mechanism can only work for countries with a single
// alternative language and ISO-based subdivision codes
// (URL example: data/CA/AB and data/CA/AB--fr).
$languages = [];
if (isset($definition['languages']) && $countryCode != 'HK') {
if ($countryCode == 'CA' && isset($definition['languages'])) {
$languages = explode('~', $definition['languages']);
array_shift($languages);
}
Expand Down Expand Up @@ -167,9 +168,9 @@ function generate_url_list()
global $serviceUrl;

$index = file_get_contents($serviceUrl);
// Get all links that start with /address/data.
// Get all links that start with /ssl-address/data.
// This avoids the /address/examples urls which aren't needed.
preg_match_all("/<a\shref=\'\/address\/data\/([^\"]*)\'>/siU", $index, $matches);
preg_match_all("/<a\shref=\'\/ssl-address\/data\/([^\"]*)\'>/siU", $index, $matches);
// Assemble the urls
$list = array_map(function ($href) use ($serviceUrl) {
// Replace the url encoded single slash with a real one.
Expand Down
13 changes: 6 additions & 7 deletions src/AddressFormat/AddressFormatRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected function getDefinitions()
'locality', 'postalCode',
],
'locality_type' => 'post_town',
'postal_code_pattern' => 'GIR ?0AA|(?:(?:AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(?:\d[\dA-Z]? ?\d[ABD-HJLN-UW-Z]{2}))|BFPO ?\d{1,4}',
'postal_code_pattern' => 'GIR ?0AA|(?:(?:AB|AL|B|BA|BB|BD|BF|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(?:\d[\dA-Z]? ?\d[ABD-HJLN-UW-Z]{2}))|BFPO ?\d{1,4}',
],
'GE' => [
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%postalCode %locality",
Expand Down Expand Up @@ -553,14 +553,13 @@ protected function getDefinitions()
'postal_code_pattern' => '\d{5}',
],
'GU' => [
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality %administrativeArea %postalCode",
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality %postalCode",
'required_fields' => [
'addressLine1', 'locality', 'administrativeArea', 'postalCode',
'addressLine1', 'locality', 'postalCode',
],
'uppercase_fields' => [
'addressLine1', 'addressLine2', 'locality', 'familyName', 'additionalName', 'givenName', 'organization', 'administrativeArea',
'addressLine1', 'addressLine2', 'locality', 'familyName', 'additionalName', 'givenName', 'organization',
],
'administrative_area_type' => 'state',
'postal_code_type' => 'zip',
'postal_code_pattern' => '(969(?:[12]\d|3[12]))(?:[ \-](\d{4}))?',
],
Expand Down Expand Up @@ -802,7 +801,7 @@ protected function getDefinitions()
'required_fields' => [
'addressLine1', 'locality', 'postalCode',
],
'postal_code_pattern' => '948[5-9]|949[0-7]',
'postal_code_pattern' => '948[5-9]|949[0-8]',
'postal_code_prefix' => 'FL-',
],
'LK' => [
Expand Down Expand Up @@ -1005,7 +1004,7 @@ protected function getDefinitions()
'postal_code_pattern' => '2899',
],
'NG' => [
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality %postalCode\n%administrativeArea",
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%dependentLocality\n%locality %postalCode\n%administrativeArea",
'uppercase_fields' => [
'locality', 'administrativeArea',
],
Expand Down

0 comments on commit 6d05301

Please sign in to comment.