Closed
Description
Symfony version(s) affected
6.4
Description
I am using the LocaleSwitcher to modify the Locale:
public function indexAction(
Request $request,
ProgramRepository $programRepository,
LocaleSwitcher $localeSwitcher,
int $id,
): Response {
if (null === $program = $programRepository->find($id)) {
throw $this->createNotFoundException();
}
$localeSwitcher->setLocale($program->getLocale());
I have a form that is created after setting the Locale. However, the labels do not come through in the correct language.

You will notice above that the Validation errors translate fine which is correct.
The correct language for the label only comes through if I specifically setLocale on the Request.
public function indexAction(
Request $request,
ProgramRepository $programRepository,
LocaleSwitcher $localeSwitcher,
int $id,
): Response {
if (null === $program = $programRepository->find($id)) {
throw $this->createNotFoundException();
}
$request->setLocale($program->getLocale());
$localeSwitcher->setLocale($program->getLocale());

Is this the intended logic? Seems strange that I would need to set the locale on the switcher as well as the Request
How to reproduce
- Create a form with translated labels
- Use the LocaleSwitcher to change the language
Possible Solution
No response
Additional Context
No response