1

I have the following code:

<ul>
    {% for item in array %}
        <li>{{ item }}</li>
    {% endfor %}
</ul>

I want to translate the item variable, I've tried using the trans tag like this:

<ul>
    {% for item in array %}
        <li>{% trans item %}</li>
    {% endfor %}
</ul>

But Django complains with a syntax error stating that it was expecting an empty or an endfor

lordscales91
  • 423
  • 1
  • 8
  • 22
  • 1
    @RahulGupta Ooops! Yeah, I didn't had that tag, now it doesn't throw a syntax error but still not works, maybe it's because I had defined the value on a dummy function as explained [here](http://stackoverflow.com/q/7625991/3107765) with a context and I have not provided one on the template – lordscales91 Oct 11 '15 at 10:04

1 Answers1

1

You need to add {% load i18n %} at the top of your template to use the trans tag.

From the docs on internationalization:

To give your template access to these tags, put {% load i18n %} toward the top of your template.

Rahul Gupta
  • 46,769
  • 10
  • 112
  • 126