How to create a translation into the "timesince" meaning? (template tag)

I am looking through the docs but I am lost ... some problems with it:

{% load i18n %}
{% blocktrans %}
{{ wpis.entry.lastChangeDate|timesince }}
{% endblocktrans %}

      

Raise:

`KeyError: u'wpis.entry.lastChangeDate | timesince'`

      

Of course, without blocktrans, everything works fine.

So what is an easy way to translate multiple words? (I am interesting Polish, minutes -> minute, hours -> godzin, etc.) I will be grateful for a clear example.

EDIT: in my .po file I have:

#: templates/part.html:37 
#, python-format 
msgid "" 
"\n" 
"%(lastChangeDate)s\n" 
msgstr "" 

      

and I don't see anything about var in the docs ... now I would do:

msgid "hours" 
msgstr "godzin" 

      

etc. and bind it to my var (example above doesn't work ...)

+2


source to share


2 answers


{% load i18n %}
{% blocktrans with wpis.entry.lastChangeDate|timesince as lastChangeDate %}
{{ lastChangeDate }}
{% endblocktrans %}

      



See http://docs.djangoproject.com/en/dev/topics/i18n/#in-template-code for details .

+2


source


Just use {{ var|timesince }}

and make sure LANGUAGE_CODE

your settings.py is set to your locale and USE_I18N

- True

.



You don't need to use blocktrans or have custom translations in the .po file for this, it's already included.

+1


source







All Articles