Skip to content

Commit

Permalink
Update Geo6.php
Browse files Browse the repository at this point in the history
Enable `withLocale()`
  • Loading branch information
jbelien committed May 11, 2018
1 parent 1f225e5 commit a6bb55c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Geo6.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function geocodeQuery(GeocodeQuery $query): Collection
throw new InvalidArgument('Address, Street Name, and Locality (or Postal Code) cannot be empty.');
}

$language = '';
if (!is_null($query->getLocale()) && preg_match('/^(fr|nl).*$/', $query->getLocale(), $matches) === 1) {
$language = $matches[1];
}

$url = sprintf($this->getGeocodeEndpointUrl(), urlencode($postalCode ?? $locality), urlencode($streetName), urlencode($streetNumber));
$json = $this->executeQuery($url);

Expand All @@ -98,16 +103,24 @@ public function geocodeQuery(GeocodeQuery $query): Collection
foreach ($feature->properties->components as $component) {
switch ($component->type) {
case 'municipality':
$municipality = $component->name_fr ?? $component->name_nl;
if ($language === 'nl') {
$municipality = $component->name_nl ?? $component->name_fr;
} else {
$municipality = $component->name_fr ?? $component->name_nl;
}
break;
case 'postal_code':
$postalCode = (string) $component->id;
break;
case 'street':
$streetName = $component->name_fr ?? $component->name_nl;
if ($language === 'nl') {
$streetName = $component->name_nl ?? $component->name_fr;
} else {
$streetName = $component->name_fr ?? $component->name_nl;
}
break;
case 'street_number':
$streetNumber = (string) $component->name_fr ?? $component->name_nl;
$streetNumber = (string) $component->name_fr;
break;
}
}
Expand Down

0 comments on commit a6bb55c

Please sign in to comment.