Translate Strings in Templates

A snippet showing how to translate template text using {% trans %}.


<!-- templates/home.html -->

{% load i18n %}
<h1>{% trans "Welcome" %}</h1>
<p>{% trans "This site supports multiple languages." %}</p>

{# Variable substitution #}
<p>{% trans "Hello %(name)s!" %} {% comment %}use with blocktrans for variables{% endcomment %}</p>
      
Explanation:
  • Load the i18n library: {% load i18n %}.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.