Translate at init time
This commit is contained in:
parent
51bf21c8b1
commit
fda3a849bf
|
@ -22,22 +22,22 @@ class RegistrationForm(UserCreationForm):
|
||||||
|
|
||||||
|
|
||||||
class FilterForm(forms.Form):
|
class FilterForm(forms.Form):
|
||||||
text = forms.CharField(max_length=128, required=False)
|
text = forms.CharField(max_length=128, required=False, label=_("Search"))
|
||||||
zipcode = forms.CharField(max_length=4, required=False)
|
zipcode = forms.CharField(max_length=4, required=False, label=_("ZIP code"))
|
||||||
distance = forms.IntegerField(required=False)
|
distance = forms.IntegerField(required=False, label=_("Distance"))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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(
|
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(
|
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(
|
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)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue