0

I created a rather simple form using Django's UpdateView class, however, now that I want it's labels to be translated into other languages, I can't figure out how to do that.

Here is the code of the view class:

class EntityUpdate(UpdateView):
    model = Entity
    template_name = "entity/settings.html"
    fields = ["enabled"]

And in my template, all i have is:

<form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="{% trans 'Save' %}" />
</form>

Where do I lookup translated strings?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Ibolit
  • 9,218
  • 7
  • 52
  • 96

1 Answers1

2

You should mark the label as translatable in the model itself.

class Entity(models.Model):
    enabled = models.BooleanField(verbose_name=_('enabled'))

(You could do the same by overriding the definition in the form, using the label argument, but doing it in the model ensures it gets translated everywhere.)

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Yep, that seemed to work. However, I am not sure I want it translated everywhere. I don't quite understand all the implications of that. – Ibolit Jun 29 '17 at 12:47
  • 1
    I just mean in every form as well as the admin. It won't be translated in code or anywhere you don't explicitly use the verbose name. – Daniel Roseman Jun 29 '17 at 12:48