【问题标题】:Use function in twig's translation在 twig 的翻译中使用函数
【发布时间】:2011-11-23 14:22:21
【问题描述】:

我翻译了包含日期的字符串。

{% trans with {'%date%': lastAcceptedDate } from "translations" %}createdBefore%date%notAccepted{% endtrans %}

现在我想格式化日期。可能是按日期功能。类似于 PHP 中的以下内容

__( 'createdBefore%date%notAccepted', 
    array(
        '%date%' => (new DateTime($lastAcceptedDate))->format('d.m. Y')
    )
);

这绝对不是工作或最佳代码。这只是对我想要实现的目标的另一种解释。

我发现我可以用像这样的普通字符串在树枝上做到这一点

{{ lastAcceptedDate | date("d.m. Y") }}

但我无法在 twig 的翻译标签中找到如何做到这一点。

【问题讨论】:

    标签: formatting symfony translation twig


    【解决方案1】:

    你试过了吗?

    {% trans with {'%date%': (lastAcceptedDate | date("d.m. Y")) } from "translations" %}createdBefore%date%notAccepted{% endtrans %}
    

    如果它有效,可能甚至不需要圆括号!

    【讨论】:

      猜你喜欢
      • 2017-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多