Home > Enterprise >  Model form labels translation
Model form labels translation

Time:02-01

I have included form labels in my translation as follows:

class GuestEmailForm(forms.ModelForm):
    class Meta:
        model = Guest
        fields = ['email']

        labels = {
            'email': _('Add your email for updates'),
        }

However, even though they show up in my translation files and I have added translations, they do not show up translated.

Is there a special way to handle labels in model forms?

CodePudding user response:

You need to work with gettext_lazy to postpone the translation process until the view is rendered.

You thus should import gettext_lazy(…) [Django-doc]:

from django.utils.translation import gettext_lazy as _
  •  Tags:  
  • Related