views:

12

answers:

1

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.

+2  A: 

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

Ignacio Vazquez-Abrams
How the tag should look like and how the text in it can be translated?
culebrón
The tag should take the hours and minutes, and it should use the normal Django i18n mechanisms.
Ignacio Vazquez-Abrams