Unfortunately it is impossible to translate a key translation in the flash bag ...
You could create a custom service with as dependencies
And then perform the translation yourself before adding the message to the flashBag
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Translation\Translator;
class FlashBagTranslator
{
/** @var Translator $translator */
private $translator;
/** @var FlashBag $flashBag */
private $flashBag;
public function __construct(Translator $translator, Session $session)
{
$this->translator = $translator;
$this->flashBag = $session->getFlashBag();
}
public function addMessage($type, $translationKey, array $parameters = [], $domain = null, $locale = null)
{
$message = $this->translator->trans($translationKey, $parameters, $domain, $locale);
if ($message === $translationKey) {
// Your translation isn't findable, do something :)
return false;
}
$this->flashBag->add($type, $message);
return true;
}
}
A little disappointing, isn't it ?