Kdyby / Translation

Integration of Symfony/Translation into Nette Framework
https://packagist.org/packages/kdyby/translation
Other
89 stars 84 forks source link

Incorrectly detected locale #193

Open roher-roher opened 1 year ago

roher-roher commented 1 year ago

Hello,

After upgrading to nette v.3.1.10 and translation v.3.0.6 I have a problem that locale is always resolved to "en", regardless of resolvers results. Here is my config.neon:

translation:
    default: en
    whitelist: [en_US, en, fr_FR, fr]
    fallback: [en_US, en]
    debugger: yes

Here is my RouterFactory:

    public static function createRouter(): RouteList {
        $router = new RouteList;
        $router[] = new Route('[<locale en|fr>/]<presenter>/<action>[/<id \d+>]', 'Main:default');
        return $router;
    }

My browser locale is 'fr', but the website is opened in English, and here is what I see in the tracy debugger:

Order of locale resolvers and final locale for each request

Main:default en
1. LocaleParamResolver
2. AcceptHeaderResolver fr

Even when I try force French locale by opening my website like this: https://example.com/fr, it's still opened in English, and here is what I see in the tracy debugger:

Order of locale resolvers and final locale for each request

Main:default en
1. LocaleParamResolver fr
2. AcceptHeaderResolver fr

Before upgrade everything worked good. Maybe now I need to change something in the code, but I don't know what. Please help :)

matlad commented 1 year ago

Same issue. I found this commit: https://github.com/symfony/translation/commit/c1cca3eb086bb62d98890631ef6bbc65ce913dd1 which is probably the source of trouble.

in method getLocale

    public function getLocale()
    {
        if (empty(parent::getLocale())) {
            $this->setLocale($this->localeResolver->resolve($this));
        }

        return parent::getLocale();
    }

Now the condition of if is always false. Because now symphony translator if ((bool) $this->locale) is false returns \Locale::getDefault() or 'en' ;