How to show a branch date in French

In my view, I want to show the date:

{{ match.date|date("ld F - H:i") }} 

This date is displayed in English:

Wednesday 15 June - 15:30

I would like to display it in French.

I tried to add setlocale(LC_TIME, "fr_FR"); used to call a view, but the date is still displayed in English ...

+5
source share
2 answers

The date filter in Twig is not suitable for localized date formatting, since it is based on PHP DateTime::format . One option would be to use the localizeddate filter instead, provided by the Intl Extension .

This extension is not supplied by default for installing Symfony. You will find it in the official Twig extension repository:

 composer require twig/extensions 

Then simply declare this extension as a service in services.yml , for example:

 services: twig.extension.intl: class: Twig_Extensions_Extension_Intl tags: - { name: twig.extension } 
+4
source

You can work with hash (an array of key values) and map it to a date object that you are manipulating.

For example, to get the day of the week today in words:

 {% set trans_day_hash = { "Monday": "Lundi", "Tuesday": "Mardi", "Wednesday": "Mercredi", "Thursday": "Jeudi", "Friday": "Vendredi", "Saturday": "Samedi", "Sunday": "Dimanche" } %} {{ trans_day_hash["now"|date('l')] }} 
+1
source

All Articles