开发者

How to make a "nested" translation string in Django template?

Here's a phrase I have to make translateable:

Poll ends in 2 hours 23 minutes

This string must have the main phrase and 'hour' and 'minute' in singular and plural forms.

{% blocktrans %}Poll ends in {{ poll.expire_hours }} ??? 开发者_高级运维{{ poll.expire_minutes }} ???{% endblocktrans %}

What do I put then instead of ??? ?


Solution: made a simple tag that takes parameters like this:

{% readable_interval _('Poll ends in %s') poll.expire %}

and inside it converts the poll.expire (timedelta) into a readable text ('X days'/'N hours and M minutes'/'N hours'/'M minutes'/'Less than a minute'). All the strings that are coded in the tag code, are i18-ized.


This type of string will bring you pain if you try to i18nize it this way. Write a template tag for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜