I am trying to render a translated date coming from an API and I am wondering what's the best way to do it.

The value coming from the API is formatted as "February 13, 2007" I would love to keep this format for english language but to have "13 Février 2007" for french and "13. Februar 2007" for german.

I tried to strtotime() the value when I receive it and |format_date() it in twig - it works but the date is printed with the medium date format (D, m/d/Y - H:i).

For this medium format, the translation works as expected, in french I see the date formated as D d/m/Y - H:i as it is set in /admin/config/regional/translate.

But I want j F Y for french, F j, Y for english, j. F Y for german. Drupal core doesn't give this format so I created a custom date-time format for the undefined language with F j, Y as value.

The problem is that I can't translate this format from /admin/config/regional/translate like it's done for the core date-time formats.

Any clue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.