Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Twig date translatable

Tags:

twig

symfony

I am displaying a DateTime object in twig like this:

<td>{{ transaction.getDate|date("F - d - Y") }}</td>

Now I want the month to be translatable, For example April - 20 - 2012 should be displayed as: Avril - 20 - 2012

Can I do this? If so, how?

I am working on Symfony2.

like image 688
Amit Avatar asked Apr 19 '12 07:04

Amit


1 Answers

or use the The Intl Extension :

{{ "now"|localizeddate('none', 'none', app.request.locale, "Europe/Paris", "cccc d MMMM Y") }}

Will give you something like :

jeudi 25 février 2016

To enable with symfony 2, add to composer :

composer require twig/extensions

And activate filters with service :

services:
    twig.extension.intl:
        class: Twig_Extensions_Extension_Intl
        tags:
            - { name: twig.extension }
like image 68
Mickaël Avatar answered Sep 18 '22 07:09

Mickaël