2

I'm using django registration and I want to translate the names of the fields and the error messages. I've realized that in /registration/locale there are files with different translations, but I don't how to use them.

This is a template example:

<table class="formulari">
<form method='post' action=''>{% csrf_token %}
    {{ form }}
    <tr><td></td><td><input type='submit' value="Actualitzar contrassenya" /></td>
</form>
</table>

I've tried with:

<form method="post" action="">{% csrf_token %}             
    <tr>
        <th> <label> Contrassenya nova </label> </th>
    <td> {{form.new_password1}} <td>

Now I can control the labels values, but I don't know how to translate the errors...

Thanks for your answers and your patience!

Alasdair
  • 298,606
  • 55
  • 578
  • 516
user2170928
  • 237
  • 1
  • 3
  • 14

2 Answers2

1
  1. On top of the template add {% load i18n %}.
  2. Replace all text labels with their counterparts that exits in english locale file.
  3. Wrap all bare text (labels) into {% trans '<text goes here>' %}

This should mark those labels for translation. Refer to django i18n documentation for details.

J0HN
  • 26,063
  • 5
  • 54
  • 85
0

Have a look here how to use language files within django. You will have to create and compile them. https://docs.djangoproject.com/en/dev/topics/i18n/translation/#message-files

Jingo
  • 3,200
  • 22
  • 29