Skip to main content

Articles tagged with "dates"

Localising dates in twig templates

14th Aug 2018

A client noticed the dates on their news articles were not being translated into the correct language. The name of the month would always appear in English, even though all the month names had themselves been translated and showed correctly elsewhere. The problem turned out to be down to the twig filter being used in the template to format the date. This is what we did have:

twig
{% set newsDate = node.getCreatedTime|date('j F Y') %}
{% trans %} {{ newsDate }}{% endtrans %}


So this would produce something like '1 March 2018' instead of '1 März 2018' when...

Read more