Translatre at init time

This commit is contained in:
Jannis Portmann 2023-05-17 15:35:33 +02:00
parent cd0a7f0199
commit 8c00d55bb6

View file

@ -22,12 +22,23 @@ class RegistrationForm(UserCreationForm):
class FilterForm(forms.Form):
text = forms.CharField(max_length=128, required=False, label=mark_safe(
f'<i class="fa-solid fa-magnifying-glass"></i> {_("Search")}'))
zipcode = forms.CharField(max_length=4, required=False, label=mark_safe(
f'<i class="fa-solid fa-location-dot"></i> {_("ZIP code")}'))
distance = forms.IntegerField(required=False, label=mark_safe(
f'<i class="fa-solid fa-signs-post"></i> {_("Entfernung")} (km)'))
text = forms.CharField(max_length=128, required=False)
zipcode = forms.CharField(max_length=4, required=False)
distance = forms.IntegerField(required=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Set the translated labels by session language with icons for each form field
self.fields['text'].label = mark_safe(
f'<i class="fa-solid fa-magnifying-glass"></i> {_("Search")}'
)
self.fields['zipcode'].label = mark_safe(
f'<i class="fa-solid fa-location-dot"></i> {_("ZIP code")}'
)
self.fields['distance'].label = mark_safe(
f'<i class="fa-solid fa-signs-post"></i> {_("Distance")} (km)'
)
class WishForm(forms.ModelForm):