fix(geocoding): support configured google maps locale in geocoding re… - #279
Conversation
Resolves the conflict in Geocoding.php. The release branch centralised geocoder construction into makeGeocoder() so a test double can be injected through the fleetops.geocoder container binding, which removed the three inline construction sites this PR edited. The locale logic now lives in makeGeocoder(), so it applies to every caller rather than being repeated. Two adjustments to the original change: Locale and region are read from separate config keys. GoogleMaps' second constructor argument is region biasing (a ccTLD such as `us`), not language — language is the StatefulGeocoder argument. Passing one value to both worked for locales that happen to also be ccTLDs (ru, es, fr) but the `en` default is not a valid region, and it replaced the null passed previously. getLocale() keeps this PR's key and drives language; getRegion() reads services.google_maps.region and drives region bias. Both getters use `?:` rather than a config() default. This key is stored in the settings table, so it exists-but-empty on installs that never filled it in, and config()'s default only applies when a key is absent entirely — a stored empty value would otherwise return null from a `: string` method and raise a TypeError on every geocode call. Also drops a duplicated docblock left above getLocale(), and adds coverage for both getters. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Resolved the conflict with Why it conflicted: the release branch centralised geocoder construction into Two adjustments worth flagging, since they change the original design: 1. Locale and region are now separate config keys. Passing one value to both works for locales that happen to also be ccTLDs (
2. Both getters use Also removed a duplicated docblock that ended up above One thing to be aware of: region bias on this path changes from Separately, and out of scope here: core-api's |
Description
Currently, Google Maps geocoding and reverse-geocoding requests in
FleetOpsalways return address details and street names in English. This happens becauseGeocoding.phphardcodes'en'as the locale forStatefulGeocoderand passesnullas the region to theGoogleMapsprovider, ignoring the system-configuredservices.google_maps.localesetting.This PR introduces dynamic locale support by retrieving the configured locale (
config('services.google_maps.locale', env('GOOGLE_MAPS_LOCALE', 'en'))) and passing it to both theGoogleMapsprovider (for region bias) and StatefulGeocoder` (for localized language response).Changes
Geocoding::getLocale()helper method to retrieve the configured locale.geocode(),reverseFromQuery(), andreverseFromCoordinates()inGeocoding.phpto usegetLocale()instead of hardcoded'en'andnullregion parameters.How to Test
Settings -> Services -> Google Maps) with API key and setgoogle_maps_localeto a non-English locale (e.g.ru,es,fr).