Django\'s internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way to translate the model name and the attributes for admin pages? I did n
Important things not mentioned in the Django documentation:
django-admin compilemessages
, e.g. as a part of your build
process. Thanks stevejalim!ugettext_lazy()
to model names ( Meta
class and verbose_name
)verbose_name
) names can also be translated with ugettext_lazy()
Example using above principles:
from django.utils.translation import ugettext_lazy as _
class Order(models.Model):
subject = models.CharField(max_length=150, verbose_name = _('Order|subject'))
description = models.TextField( verbose_name = _('Order|description'))
class Meta:
verbose_name = _('order')
verbose_name_plural = _('orders')
Or is there a better way to translate the model and admin pages?
Either way we should enhance the Django documentation and fill the gap!
See https://automationpanda.com/2018/04/21/django-admin-translations/ It's author made an excellent work in showing how to master all django translation features step by step. It's much better than oficial documentation to me.