V
V
vikholodov2018-04-24 10:59:59
Django
vikholodov, 2018-04-24 10:59:59

How to do localization in Django models?

Good day, colleagues!
Such a question: It is
quite clear how the translation of strings is done in views and templates. But either I'm looking badly, or actually in the office. The documentation doesn't say anything about translating strings in model instances. The application will support a bunch of languages, from English to some French, how is this implemented in practice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Grigoriev, 2018-04-24
@vikholodov

Use the third party app django-modeltranslation . After setting, for the specified fields in the admin panel, additional fields will appear for translation into another language.
There is also a django-hvad application . It differs from the previous one in that tabs for each language will appear in the admin panel. With a large number of languages, this is even more convenient.

S
Sergey Gornostaev, 2018-04-24
@sergey-gornostaev

Really bad looking. The official documentation has examples of model internationalization.

from django.db import models
from django.utils.translation import gettext_lazy as _

class MyThing(models.Model):
    name = models.CharField(_('name'), help_text=_('This is the help text'))

    class Meta:
        verbose_name = _('my thing')
        verbose_name_plural = _('my things')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question