Skip to content
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

Incorrectly detected locale #193

Open
roher-roher opened this issue Mar 12, 2023 · 1 comment
Open

Incorrectly detected locale #193

roher-roher opened this issue Mar 12, 2023 · 1 comment

Comments

@roher-roher
Copy link

roher-roher commented Mar 12, 2023

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
Copy link

matlad commented Jun 8, 2023

Same issue.
I found this commit: symfony/translation@c1cca3e 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' ;

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

No branches or pull requests

2 participants