[Django]-Django {% blocktrans %}: How to handle pluralization inside a for loop?

5👍

Probably, you forgot to load translation tags. Add following line at the top of your template:

{% load i18n %}

After you fix that, note that for a blocktrans tag after count a variable, whose value will serve for plural detection, should be specified, so you probably need something like

{% blocktrans count count=forloop.counter %}
👤alko

6👍

Here is the working code, thanks to alko:

{% load i18n %}

<!-- ... -->

{% if forloop.last %}
    <h4>
        {{ forloop.counter }}
        {% blocktrans count count=forloop.counter %}
             Valued Customer
        {% plural %}
             Valued Customers
        {% endblocktrans %} 
    </h4>
{% endif %}
👤pete

1👍

To pluralize use this:

Customer{{ forloop.counter|pluralize }}
👤Arpit

Leave a comment