Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow locale change with cache #103

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

Closed
wants to merge 0 commits into from
Closed

Allow locale change with cache #103

wants to merge 0 commits into from

Conversation

AntoineLemaire
Copy link
Contributor

To allow dynamic locale changes

$result = $geocoder->using('cache')->setLocale('fr_FR')->geocode('Paris 15, France');
$result = $geocoder->using('cache')->setLocale('en_FR')->geocode('Paris 15, France');

@AntoineLemaire
Copy link
Contributor Author

It seams to have the same logical problem as geocoder-php/Geocoder#408 (comment), but don't know yet how reset locale after use geocode

$result = $geocoder->using('cache')->geocode('Paris 15, France'); //Locale NULL
$result = $geocoder->using('cache')->setLocale('de_DE')->geocode('Paris 15, France'); //Use locale de_DE
$result = $geocoder->using('cache')->geocode('Paris 15, France'); //Use locale de_DE

or maybe add after $data = $this->provider->geocode($address);

if (null !== $this->getLocale() && $provider instanceof LocaleAwareProvider) {
    $this->provider->setLocale(null);
}

But seams uggly

@willdurand
Copy link
Member

poke @Baachi

@Baachi
Copy link
Member

Baachi commented Feb 26, 2016

As i said in the linked PR, I'm not a big fan of it, because it will lead to errors and the symfony/dependency-injection made it very simple to build different providers.

Anyways, here another approach:

We can extend the addProvider method and accept that locale can be an array. If the locale parameter is an array, build x Providers and change the name to: <myname_<local>.

This would looks like this:

bazinga_geocoder:
    providers:
        google_maps:
            locale: [de_DE, en_US, ru_RU]

and in the controller you can now use:

$this->geocoder->using('geocoder_deDE')->geocode('Alexander Platz, Berlin');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants