Translate at init time

pull/7/head
Jannis Portmann 2023-05-17 15:47:58 +02:00
parent 51bf21c8b1
commit fda3a849bf
1 changed files with 7 additions and 7 deletions

View File

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