pythonpython-3.xdjangodjango-models

What is gettext_lazy on django for?


I have read on the documentation of Django about gettext_lazy, but there is no clear definition for me about this exact function, and I want to remove it.

I found this implementation:

from django.utils.translation import gettext_lazy as _

and it is used on a django model field in this way:

email = models.EmailField(_('email address'), unique=True)

What is it for?

What happens if I remove it?


Solution

  • Its used for translation for creating translation files like this:

    # app/locale/cs/LC_MESSAGES/django.po
    
    
    #: templates/app/index.html:3
    msgid "email address"
    msgstr "emailová adresa"
    

    Then it can be rendered in template as translated text. Nothing will happen if you remove it and don't want to use multilingualism.