I need to render documents in different languages. Therefore I used to use the following code:
use Symfony\Component\Translation\TranslatorInterface;
....
$this->translator->setLocale($documentData->getLocale());
$html = $this->templating->render('admin/request/pdf/document.pdf.twig', [
'data' => $data,
]);
...
And everything worked fine.
But then "Symfony\Component\Translation\TranslatorInterface" got deprecated and one should use "Symfony\Contracts\Translation\TranslatorInterface". In the new class there is no "setLocale()" anymore.
I tried a lot of things but I finally have no idea to work around.
Did anyone mange it?
Thanks a lot!
EDIT:
I am looking for a solution where I can set the translation locale for the Twig template globally. Actually I don't want to write this for every key in the twig:
{{ 'pdf.document.title'|trans({}, 'documents', locale) }}
I want to write this like before:
{{ 'pdf.document.title'|trans }}
Symfony 5. As long as your website always starts with your domain name and de first two characters after that is de locale of the current user one can create in twig an url with the locale of the requester and replace/substitute it with the locale of the receiver. Not nice but it works (for me).