Block Translation in Templates
A snippet showing how to translate dynamic text blocks in templates.
<!-- templates/account_welcome.html -->
{% load i18n %}
{% blocktrans with user_name=user.first_name login_count=user.login_count %}
Hello {{ user_name }}, you have logged in {{ login_count }} times.
{% endblocktrans %}
{% blocktrans count item_count=items|length %}
There is {{ item_count }} item in your cart.
{% plural %}
There are {{ item_count }} items in your cart.
{% endblocktrans %}
Explanation:
-
Use
withto pass variables; usecount/pluralfor plural forms.
- Category Internationalization (i18n)
- Total Views 760
- Last Modified 11 June, 2026
- Tags #i18n #translation #blocktrans #templates
Previous snippet