Parsing of addresses in the format of different countries
CiviCRM has the ability to parse addresses into a street name, house number and street unit. This parsing is based on I assume US address formats.
E.g. an address like 799 E DRAGRAM SUITE 5A is parsed into house number: 799, street name: E Dragram, and Street unit Suite 5a.
In the Netherlands and Belgium the adresses are formatted in a different way, first it is the street name, then the house number and then the street unit.
Some examples:
- Grote straat 1a, which should be parsed to Street name: Grote straat, house number 1, and street unit a
- Grote straat 2-3, which should be parsed to Street name: Grote straat, House number 2, and street unit 3
- Plein 40-45 60-II, which should be parsed to Street name: Plein 40-45, house number 60 and street unit II
What I think CiviCRM should be capable of (either with an extension or in core):
- Parse addresses based on the country of the address
- Format addresses based on the country of the address, meaning glue the individual address (Street name, house number, street unit) parts into one address
How does it work currently?
When I enable Address Parsing I can enther a full address into CiviCRM.
If I enter Grote straat 1a it gets parsed into Address name: Grote straat 1a, House number: empty and street unit empty If I enter Plein 40-45 60-II it gets parsed into Address name: Plein 40-45 60-II, House number: empty and street unit empty
If I enter the individual parts, street name: Grote straat, house number: 1 and street unit a, it gets formatted to 1 Grote straat a
As you can see the formatting and parsing of Dutch and Belgium addresses does not work.
Proposed solution
I do think it will be good when the address parsing functionality could be made in such way that extensions could hook into it.
I am thinking of a hook which provides callback functions for address parsing based on the country ID of the address.
Example code
$callbacks[1020] = array('CRM_Address_BAO_Address', 'parseBelgiumAddress');
$callbacks['default'] = array('CRM_Address_BAO_Address', 'parseAddress');
/**
* Alter the callbacks for address parsing
*
* @param array $callbacks
*/
hook_civicrm_alter_address_parser_callbacks(&$callbacks) {
// Add a custom address parser
// For example the dutch one:
$callbakcs[1152] = array('CRM_MyExtension_DutchAddressParser', 'parseDutchAddress');
}
This way CiviCRM core could provide a default address parser, and a set of address parser for certain countries and if one is missing an extension developer could write the missing parser.
What do you think of this? If everyone is happy I am happy to implement this.