I have a form that I want to translate:
Models.py:
class Show(models.Model):
discount_tickets = models.IntegerField("Discount Tickets")
regular_tickets = models.IntegerField("Regular Tickets")
afillate_price = models.IntegerField("Afillate Price")
user_price = models.IntegerField("User Price")
start_time = models.CharField("Event Time", max_length=20)
sale_end_time = models.CharField("Sale End Time", max_length=20)
def __unicode__(self):
return unicode(self.discount_tickets)
class ShowForm(ModelForm):
pass
class Meta:
model = Show
How can I translate the field names?
{% load i18n %} is needed for internationalization. The purpose of internationalization is to allow a single application to read in multiple languages. In order to do this: you need a few hooks called translation strings. To give your template access to these tags, put {% load i18n %} toward the top of your template..
gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django's startup); gettext_lazy translates the strings in a lazy fashion, which means, eg.
Django then provides utilities to extract the translation strings into a message file. This file is a convenient way for translators to provide the equivalent of the translation strings in the target language. Once the translators have filled in the message file, it must be compiled.
from django.utils.translation import ugettext_lazy as _
class Show(models.Model):
discount_tickets = models.IntegerField(_("Discount Tickets"))
regular_tickets = models.IntegerField(_("Regular Tickets"))
afillate_price = models.IntegerField(_("Afillate Price"))
user_price = models.IntegerField(_("User Price"))
start_time = models.CharField(_("Event Time"), max_length=20)
sale_end_time = models.CharField(_("Sale End Time"), max_length=20)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With