doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 9 forks source link

Add setting to override the Google API language #18

Closed carlcs closed 3 years ago

carlcs commented 3 years ago

This allows to force a language that is used for the Google API calls. When the setting is not set, Google API continues using the browser language.

https://developers.google.com/maps/documentation/javascript/localization

Our use case for this setting is to get consistent lookup results in address fields for all users. Currently with Google Maps plugin we’re getting, for example, “Germany” for country address part when a user has the browser setup in English and “Deutschland” for users with a German browser.

In Smart Map we were always getting English results, because request were made from the server instead of the browser.

carlcs commented 3 years ago

Hi @lindseydiloreto, I cleaned up the PR a bit, and fixed the issue where it wasn’t possible to override the API language by passing in the parameter to ApiHelper::getApiUrl(). I also did a rebase ontop of the latest version.

lindseydiloreto commented 3 years ago

Hey @carlcs, thanks for this! For the most part, it all looks great. Thanks for even going back and cleaning up the loose ends.

My only disagreement is in where the language is being stored... In my opinion, each language override should be handled separately, at the field level. So instead of having a sitewide language specification, each Address field could individually have a separate language.

There may be some weird edge cases where people want different Address fields to operate in different languages. I also want to avoid any confusion that the Google Maps plugin would be handling the language of front-end maps (because it won't).

I'll accept this PR and make a few tweaks. I plan on moving the language setting to the field level, which will of course require some UI adjustments. Feel free to use your forked version until the proper fix is in place (hopefully within 2-4 weeks)!

Thanks again! 🍺

lindseydiloreto commented 3 years ago

Just a heads up, a variation of this has been formally added in v4.0.5! 👍

You were right about needing to make this a global setting, it couldn't possibly be localized to each individual Address field. All Address fields share the same Google API URL, which is where those parameters need to be applied. So regardless of where it is stored in the plugin, that info can only be loaded once per page.

Thanks for putting in the hard work to get an initial version going! Let me know if you have any questions about the final implementation.