python-3.xdjangodjango-models

What's gettext_lazy on django is for?


Maybe is a dummy question but i have read on the documentation of Django about the gettext_lazy, but there is no clear definition for me about this exact function and i want to remove it

and i found this implementation

from django.utils.translation import gettext_lazy as _

and is used on a django model field in this way

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

what's is for? what's happen 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"
    

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