如何使 Twig 日期可翻译 [英] How to make a Twig date translatable

查看:37
本文介绍了如何使 Twig 日期可翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样在树枝中显示一个 DateTime 对象:

I am displaying a DateTime object in twig like this:

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

现在我希望月份可以翻译,例如 April - 20 - 2012 应该显示为:Avril - 20 - 2012

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

我可以这样做吗?如果是这样,如何?

我正在开发 Symfony2.

I am working on Symfony2.

推荐答案

或使用 国际扩展:

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

会给你类似的东西:

jeudi 25 février 2016

要启用 symfony 2,请添加到 composer :

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 }

这篇关于如何使 Twig 日期可翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆