Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Marking strings as translatable


With all the prep work out of the way, let's modify the templates we created to be multilingual. Instead of the hardcoded English text that we put in our file earlier, let's start marking the field labels as translation strings. Basically, we're using a Django template tag to say "insert the translation here".

The list template is easy to work with as we only have to make two replacements. Replace the highlighted lines in templates/contactlist/entry_list.html:

{% load i18n %}
<h1>{% trans "Contact List" %}</h1>
<ol>
{% for object in object_list %}
  <li><a href="/contact/{{ object.id }}">{{ object }}</li>
{% endfor %}
</ol>

The first line loads the library file for internationalization, in the same way as loading any tag library. The second line is where we mark the text Contact List as a translation string.

Our changes haven't done much and if you view the URL in a browser, nothing will appear to have changed. Now that...