commerceguys / addressing

A PHP addressing library, powered by CLDR and Google's address data.
MIT License
922 stars 135 forks source link

Country appears twice in postal label formatted address for Guernsey, Gibraltar, Jersey and Singapore #137

Closed neilcrookes closed 4 years ago

neilcrookes commented 4 years ago

This test is for a label from the UK to the Jersey Tourist Information Board office address in Jersey...

$addressFormatRepository = new CommerceGuys\Addressing\AddressFormat\AddressFormatRepository();
$countryRepository = new CommerceGuys\Addressing\Country\CountryRepository();
$subdivisionRepository = new CommerceGuys\Addressing\Subdivision\SubdivisionRepository();
$formatter = new CommerceGuys\Addressing\Formatter\PostalLabelFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository, ['locale' => 'en']);
$address = new CommerceGuys\Addressing\Address();
$address = $address->withCountryCode('JE')->withAddressLine1('Suite 1, Liberation Station, Esplanade')->withLocality('St Helier')->withPostalCode('JE2 3AS');
echo $formatter->format($address, ['origin_country' => 'GB']);

// Suite 1, Liberation Station, Esplanade
// ST HELIER
// JERSEY             <<< here
// JE2 3AS
// JERSEY             <<< and here

As you can see, JERSEY appears duplicated in the address, before and after the postcode.

This is because the format includes the word JERSEY hardcoded in the format string.

"%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality\nJERSEY\n%postalCode"

See also this test for a label from the UK to the Singapore Tourist Information Board office address in Singapore...

$address = new CommerceGuys\Addressing\Address();
$address = $address->withCountryCode('SG')->withAddressLine1('1 Orchard Spring Ln, Tourism Court')->withPostalCode('247729');
echo $formatter->format($address, ['origin_country' => 'GB']);

// 1 Orchard Spring Ln, Tourism Court
// SINGAPORE 247729             <<< here
// SINGAPORE                    <<< and here
bojanz commented 4 years ago

Let's look at the UPU data (which Google tends to use as a base) for an explanation of current usage.

Guernsey and Jersey: http://www.upu.int/fileadmin/documentsFiles/activities/addressingUnit/jeyEn.pdf http://www.upu.int/fileadmin/documentsFiles/activities/addressingUnit/ggyEn.pdf

Jersey Post
Postal Head Quarters
JERSEY
JE1 1AA
CHANNEL ISLANDS 

Notice "Channel Islands" as the country. These two UPU entries were made on 03/2005, while both territories were assigned ISO codes in 2006, introducing the duplication.

However, the sites of their post offices still have the hardcoded phrases: https://www.jerseypost.com/

Jersey Post
Postal Headquarters
JERSEY
JE1 1AA

https://www.guernseypost.com/contact-us

Guernsey Post Ltd
Envoy House
La Vrangue
St Peter Port
GUERNSEY
GY1 1AA

The entry for Gibralta actually shows "Gibraltar" twice in the examples: http://www.upu.int/fileadmin/documentsFiles/activities/addressingUnit/gibEn.pdf However, if I go to the site of their post office: https://post.gi/contact/ I get this:

Royal Gibraltar Post Office
Postal Headquarters
104 Main Street
GX11 1AA
GIBRALTAR

No hardcoded "Gibraltar".

Here's Singapore: http://www.upu.int/fileadmin/documentsFiles/activities/addressingUnit/sgpEn.pdf

Ms. Tan Bee Soo
16 Sandilands Road
SINGAPORE 546080
REP. OF SINGAPORE 

The country name given is "Rep. of Singapore', but CLDR uses just "Singapore", creating the duplication. If I go to their post office, I do see Singapore used in front of the postal code: https://www.singpost.com/list-of-post-offices

Of course, this doesn't paint the complete picture because these addresses are for local usage. Since we default to always outputting the country name, I would lean towards just removing the hardcoded Jersey/Guernsey/Gibraltar lines. However, I am unsure what to do with Singapore.

neilcrookes commented 4 years ago

If you could remove the hardcoded Jersey/Guernsey/Gibraltar lines, that'd be a great start. Many thanks.

BenWalters commented 4 years ago

@bojanz has any progress been made on this issue please?

bojanz commented 4 years ago

Sorry for the slow turnaround on this issue. Now fixed for all mentioned countries, plus the Aland Islands. Tagging v1.0.9 with the fix included.