0

I have a Symfony 4 application in which I generate a PDF file using dompdf. In my twig files, I use localizeddate to display a date. I want my date to be written in French.

<div>
    Date :
    <span>{{ myCustomDate | localizeddate('long', 'none') }}</span>
</div>

I use the twig template in two different services: one called by my browser, the other using Messenger.

When I generate the PDF by using the "regular" browser way, the date is written in French.

Date : 12 décembre 2020

But when I generate it using Messenger, the date is in English.

Date : December 12, 2020

Would you know why?

darckcrystale
  • 1,582
  • 2
  • 18
  • 40
  • set the locale `localizeddate('long', 'none', 'fr')` – Lawrence Cherone Dec 12 '20 at 20:07
  • 1
    The reason why is the translator gets the locale from the request if not explicitly specified. As far as I know, the request context is not passed to messenger. You can pass the locale manually and then use `localizeddate('long', 'none', my_locale)` where `my_locale` would be the variable you passed along. – Julien B. Dec 12 '20 at 20:39

0 Answers0