#61804·symfony

[FlashBag] Add translation feature

Author: OlivierLejeune59Created Sep 21, 2025Updated Sep 17, 2026
LabelsFeatureHttpFoundationTranslationStalled

Description

Hello,

I would be great (if it is possible) to can use flashbag with translations options directly. Actually we are obliged to inject TranslationInterface in constructor of the controller.

example: messages.en.yaml

yaml
hello: "Hello {name} !"

actually in Controller we have to write

php
public function __construct(
    private readonly TranslatorInterface $translator,
) {
}

#[Route('/', name: 'app_test')]
public function index(Request $request): Response
{
    $this->addFlash('success', $this->translator->trans('hello', ['{name}' => 'Olviier']));
    return $this->render('test/index.html.twig',);
}

it would more simple to can write this et so no more need to inject the TraslatorInterface

php
#[Route('/', name: 'app_test')]
public function index(Request $request): Response
{
    $this->addFlash('success', 'hello', ['{name}' => 'Olviier'], 'translation_domain');
    return $this->render('test/index.html.twig',);
}

Example

No response