'blocktrans' doesn't allow other block tags (seen u'plural') inside it

2,576 views
Skip to first unread message

Tipan

unread,
Feb 5, 2009, 5:21:15 PM2/5/09
to Django users
Can anyone explain the strange behaviour I'm seeing in this
translation tag. I've translated the whole site and used the {% plural
%} tag notation as defined in the documentation, however, I'm getting
this error and I can't determine quite what I've done wrong. I'm sure
it's me, not a bug, but I'me a bit perplexed I'm afraid.

Docs show:
{% blocktrans count list|length as counter %}
There is only one {{ name }} object.
{% plural %}
There are {{ counter }} {{ name }} objects.
{% endblocktrans %}

My template has:
{% blocktrans with user_points_value as user_points_value_t %}That's
{{ user_points_value_t}} entry.{% plural %}That's
{{ user_points_value_t}} entries.{% endblocktrans %}

Throws a template syntax error:
'blocktrans' doesn't allow other block tags (seen u'plural') inside it

Exception Value:
'blocktrans' doesn't allow other block tags (seen u'plural') inside it

Any advice welcome

Rgds, Tim

Arien

unread,
Feb 5, 2009, 6:11:56 PM2/5/09
to django...@googlegroups.com
On Thu, Feb 5, 2009 at 4:21 PM, Tipan <t...@ortengo.co.uk> wrote:
> [...]

>
> Docs show:
> {% blocktrans count list|length as counter %}
> There is only one {{ name }} object.
> {% plural %}
> There are {{ counter }} {{ name }} objects.
> {% endblocktrans %}
>
> My template has:
> {% blocktrans with user_points_value as user_points_value_t %}That's
> {{ user_points_value_t}} entry.{% plural %}That's
> {{ user_points_value_t}} entries.{% endblocktrans %}
>
> Throws a template syntax error:
> 'blocktrans' doesn't allow other block tags (seen u'plural') inside it

You want to use "count" instead of "with" in the blocktrans tag:

>>> from django.template import Context, Template
>>> t = Template("""
... {% load i18n %}
... {% blocktrans count user_points_value as user_points_value_t %}
... That's {{ user_points_value_t}} entry.
... {% plural %}
... That's {{ user_points_value_t}} entries.
... {% endblocktrans %}
... """)
>>> print t.render(Context({'user_points_value': 1})).strip()
That's 1 entry.
>>> print t.render(Context({'user_points_value': 2})).strip()
That's 2 entries.

Cheers,


Arien

Tipan

unread,
Feb 6, 2009, 2:06:21 AM2/6/09
to Django users
Thanks Arien. It's a subtle difference but clearly I'd read and not
understood. Duh! Looks obvious now.
Much appreciated.Tim
Reply all
Reply to author
Forward
0 new messages