开发者

mark lables for translation in Django Forms

开发者 https://www.devze.com 2023-02-14 09:53 出处:网络
Let\'s say I have this form: class RSVPForm(forms.Form): attending_dinner= forms.ChoiceField(_(\'attending_dinner\'), c开发者_开发问答hoices=VISIBLE_ATTENDING_CHOICES, initial=\'yes\', widget=forms.

Let's say I have this form:

class RSVPForm(forms.Form):
  attending_dinner= forms.ChoiceField(_('attending_dinner'), c开发者_开发问答hoices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
  attending_brunch = forms.ChoiceField(choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
  number_of_guests = forms.IntegerField(initial=0)

How can I mark the fields' names ex. attending_dinner for translation ?


here is the answer:

from django.utils.translation import ugettext, ugettext_lazy as _

class RSVPForm(forms.Form):
attending_dinner= forms.ChoiceField(label=_('attending_dinner'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
attending_brunch = forms.ChoiceField(label=_('attending_brunch'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
number_of_guests = forms.IntegerField(initial=0)
comment = forms.CharField(max_length=255, required=False, widget=forms.Textarea)
0

精彩评论

暂无评论...
验证码 换一张
取 消