gpt4 book ai didi

symfony - twig 时间前输出 'diff.ago.day'

转载 作者:行者123 更新时间:2023-12-02 18:53:04 24 4
gpt4 key购买 nike

使用Symfony2.8日期是DateTime对象

Twig

{{ event.createDate|time_diff }}

服务.yml

twig.extension.date:
class: Twig_Extensions_Extension_Date
arguments: ["@translator"]
tags:
- { name: twig.extension }

输出不像“ago”,而只是“diff.ago.day”。在 twig dump 中也显示了这个字符串。怎么了?

最佳答案

我认为您忘记在应用程序中实际进行翻译。

This is a good resource to reference.

其中说:

(if the translations folder doesn't exist, then create it). For example, the following file (app/Resources/translations/date.de.xliff) provides the translation for our dates in German:

他们就该翻译的内容给出了一个很好的例子。

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="diff.ago.year">
<source>diff.ago.year</source>
<target>vor einem Jahr|vor %count% Jahren</target>
</trans-unit>
<trans-unit id="diff.ago.month">
<source>diff.ago.month</source>
<target>vor einem Monat|vor %count% Monaten</target>
</trans-unit>
<trans-unit id="diff.ago.day">
<source>diff.ago.day</source>
<target>vor %count% Tag|vor %count% Tagen</target>
</trans-unit>
<trans-unit id="diff.ago.hour">
<source>diff.ago.hour</source>
<target>vor einer Stunde|vor %count% Stunden</target>
</trans-unit>
<trans-unit id="diff.ago.minute">
<source>diff.ago.minute</source>
<target>vor einer Minute|vor %count% Minuten</target>
</trans-unit>
<trans-unit id="diff.ago.second">
<source>diff.ago.second</source>
<target>vor einer Sekunde|vor %count% Sekunden</target>
</trans-unit>
<trans-unit id="diff.empty">
<source>diff.empty</source>
<target>jetzt</target>
</trans-unit>
<trans-unit id="diff.in.second">
<source>diff.in.second</source>
<target>in einer Sekunde|in %count% Sekunden</target>
</trans-unit>
<trans-unit id="diff.in.hour">
<source>diff.in.hour</source>
<target>in einer Stunde|in %count% Stunden</target>
</trans-unit>
<trans-unit id="diff.in.minute">
<source>diff.in.minute</source>
<target>in einer Minute|in %count% Minuten</target>
</trans-unit>
<trans-unit id="diff.in.day">
<source>diff.in.day</source>
<target>in einem Tag|in %count% Tagen</target>
</trans-unit>
<trans-unit id="diff.in.month">
<source>diff.in.month</source>
<target>in einem Monat|in %count% Monaten</target>
</trans-unit>
<trans-unit id="diff.in.year">
<source>diff.in.year</source>
<target>in einem Jahr|in %count% Jahren</target>
</trans-unit>
</body>
</file>
</xliff>

当然,如果您想要英语版本,那么该文件应该是 app/Resources/translations/date.en.xliff 并且当然您可以将上面的德语替换为您的英语版本自己的品味/选择。

干杯

关于symfony - twig 时间前输出 'diff.ago.day',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53156406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com