To format a date in twig you usually use something like:
{{ meeting.date|date("m/d/Y") }}
Now, I have to localize this date (US m/d/y, NL d/m/y). What would be the best practice to do this in the twig? I do use Symfony 2, a workaround would be to do the translation in the controller but i would like to do this in the twig.
I didn't want to install a whole extensions just for this stuff and need to do a few things automatically: It's also possible to write a helperclass (or expand an existing helper) in Bundle/Twig/Extensions for example like this:
twig-Template:
The result is "12. February 2014" (or "12. Februar 2014" in de_DE and so on)
I really only wanted the day & month names to be translated according to the locale and wrote this twig extension. It accepts the normal
DateTime->format()
parameters and converts day & months names usingstrftime()
if needed.What about the Intl Twig extension?
Usage in a twig template: