I would like to display a date in TWIG in German.
{{ event.beginnAt |date('l d.m.Y')}}
But the output is "Friday 28.06.2013".
Where should I use the setlocale function that displays the date in German?
I would like to display a date in TWIG in German.
{{ event.beginnAt |date('l d.m.Y')}}
But the output is "Friday 28.06.2013".
Where should I use the setlocale function that displays the date in German?
You can use
setlocale()
andstrftime()
, using something Symfony-specific might be overhead.In order to achieve that I used the SonataIntlBundle it exposes some twig function that are formatted with intl.
Example:
will output
I used a simpler approach since I forced the local of the php execution context and, after that, just replaced the date function by format_datetime. Remember to see the supported patterns as they differ from the strftime. You have a link on the SonataIntlBundle for that.
You need to enable twig intl extension (it requires enabled intl functions in php) a then you just use:
Edited:
If you want to just localized name of day, you can create your own Twig extension:
src/Acme/Bundle/DemoBundle/Twig/DateExtension.php
Then register it in services.yml
src/Acme/Bundle/DemoBundle/Resources/config/services.yml
In your Twig template you can use just: