New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct handling of localized addresses #7943
Comments
PR available at #7944. |
Here's also some documentation on how to use the new feature if you are using it outside of the address attribute. The address attribute itself works out of the box preserving the backwards compatibility with the components it was using before as well as preserving the same address output format as was defined previously by concrete5. DocumentationWith all of the documentation examples you will need the address format service to be available: <?php
$af = Core::make('Concrete\Core\Localization\Service\AddressFormat');
?> Format an address with HTML<p>Our address is:</p>
<?php
echo $af->format([
'address1' => '123 Fake St.',
'city' => 'Portland',
'state_province' => 'OR',
'country' => 'US',
'postal_code' => '90000',
]);
?> Output will be: <p>Our address is:</p>
<div class="ccm-address-text">
<span class="address-line1">123 Fake St.</span><br>
<span class="locality">Portland</span>, <span class="administrative-area">Oregon</span> <span class="postal-code">90000</span><br>
<span class="country">United States</span>
</div> Format an address with text<?php
echo 'Our address is:' . "\n";
echo $af->format([
'address1' => '123 Fake St.',
'city' => 'Portland',
'state_province' => 'OR',
'country' => 'US',
'postal_code' => '90000',
], 'text');
?> Output will be: Our address is:
123 Fake St.
Portland, Oregon 90000
United States Format an address outside of US<?php
echo 'Our address is:' . "\n";
echo $af->format([
'address1' => 'Olematonkatu 1 A',
'city' => 'Helsinki',
'country' => 'FI',
'postal_code' => '00100',
], 'text');
?> Output will be: Our address is:
Olematonkatu 1 A
00100 Helsinki
Finland Format the address country with a specific locale<?php
echo 'Our address is:' . "\n";
echo $af->format([
'address1' => '123 Fake St.',
'city' => 'Portland',
'state_province' => 'OR',
'country' => 'US',
'postal_code' => '90000',
], 'text', 'fi_FI');
?> Output will be: Our address is:
123 Fake St.
Portland, Oregon 90000
Yhdysvallat Default locale is the currently active locale. Get used address fields for a country<?php
echo 'Used fields in the US:' . "\n";
foreach ($af->getCountryAddressUsedFields('US') as $field) {
echo $field . "\n";
}
?> Output will be: Used fields in the US:
address1
address2
city
postal_code
state_province Get required address fields for a country<?php
echo 'Required fields in the US:' . "\n";
foreach ($af->getCountryAddressRequiredFields('US') as $field) {
echo $field . "\n";
}
?> Output will be: Required fields in the US:
address1
city
postal_code
state_province |
Thanks! |
I'm very happy to hear address format localization improved.
Output should be:
Yes, the order of address segments is reversed in Japan. |
@hissy #8030 should fix that issue. However, the Google metadata suggests the address line should be on its own line as defined by: So the output format of the example address you gave would be:
If you think this is incorrect, you'll need to report this issue upstream to: That is actually the repo for the C++/Java implementation of the same thing but it seems to be the only "official" place to report these issues (as other people have done as well). |
This format is really nice for us. Super cool! Thank you! |
Background
Concrete5 has shipped with the address attribute for as long as I can remember. As good as the default attribute works for the North American countries, or any other countries that have states/provinces, it does not currently consider countries that do not generally use the states provinces for the address fields. It also does not consider country specific formatting of addresses.
Every time we've needed the address attribute anywhere, we've always needed to customize it for each and every project. This just does not feel correct as many other things work well out of the box. We just recently finished a project where we then noticed it was not possible to enter location data because of the required state/province field (well, it's possible but requires to put something unnecessary in that field which we are not even displaying).
Problem
The main problems I want to solve with the current address attribute:
For example, the following US address would format correctly with the default address attribute, as this is the format it is currently designed for:
But the following address would format incorrectly with the default address attribute (correct formatting below):
Solution
Google has been kind enough to open their address validation metadata for public and they themselves are using it in all sorts of applications, including Chrome.
With this metadata, it is possible to:
This has also been nicely packaged together for PHP in the commerceguys/addressing project. People from Google have particularly noted that there are no restrictions on the data and it can be included in this particular PHP library.
My suggestion is to integrate this library to concrete5 and let the address attribute get the necessary information from that library. I have a reference implementation ready that I will be shortly opening a PR for.
I believe this would fit well with the other localization functionality already baked in (such as CLDR through Punic).
Further Information
This is something that I would believe bothers everyone needing to deal with addresses and who is outside of the North American countries (or any other place without states/provinces, where the output formatting could still differ).
Just for reference, some information how many people may get annoyed by modifying the address attribute that currently ships with concrete5:
This data was extracted using the PHP library linked above.
The text was updated successfully, but these errors were encountered: