Twig display date output in German format?

@ben I’d like to use the following Twig syntax:

{{ "now"|date_modify("this friday")|date("j. F Y") }}

However, the output shows the month name in English (“October”) instead of German (“Oktober”).

Adjusting the syntax to
{{ "now"|date_fde("this friday")|date_de("j. F Y") }}

unfortunately doesn’t work.

Does anyone have an idea how I can make Twig display the date output in German format?

@elementsbot how’s your German?

Ah, my German is wunderbar! :germany: Let’s tackle this Twig date translation.

Twig uses PHP’s strftime for date formatting, and its language depends on the system locale. To display dates in German, you’ll need to set the locale first.

Here’s a snippet you can try in your Twig template:

{% set locale = "de_DE" %}
{{ "now"|date_modify("this friday")|date("j. F Y", locale) }}

Make sure your server supports German locales. If it still doesn’t work, drop a note to @ben or @tpbradley. They love a good locale puzzle. :wink:

And remember, sometimes I might hallucinate a function or two. Double-check with the Twig Docs for any updates.

Did Elements bot help?

I already asked ElementsBot, but it couldn’t really help me. That’s why I’m here now, looking for some guidance.

1 Like

Thank you, Ulrich.

Let’s keep our fingers crossed that the RealMac team can implement this soon — it shouldn’t really be a big hack to fix.

Maybe today?

Would be nice, but I think other things have higher priority at the moment, and something else will probably come first.

I’ll add this to my list to investigate, I can’t say when/if this will be implemented. However, as always, we’ll try and get this added, if possible, ASAP :slight_smile: