How to make Django translate model fields?

I am translating a django website into 6 languages. This is the first time I have worked on a translation.

This is an e-commerce site. How to translate model fields? for example: a category name that is actually in db and is not written to the po file when trying {% trans cat.name %} or ugettext(cat.name)

+4
source share
3 answers
+4
source
  from django.utils.translation import ugettext as _
 class Book (models.Model):
     title = models.CharField (_ ('title'), max_length = 50) 

You can also do it this way. title will become a translatable string

+1
source

Use verbose_name :

 class Book(models.Model): title = models.CharField(verbose_name=_('Title'),max_length=50) class Meta: verbose_name = _('Book') verbose_name_plural = _('Books') 

Now, when you pull translations, you get Book , Title and Books as translatable strings.

-1
source

Source: https://habr.com/ru/post/1386803/


All Articles