From 8c00d55bb6445eb19f355ef84a9759ef3fce3c72 Mon Sep 17 00:00:00 2001 From: Jannis Portmann Date: Wed, 17 May 2023 15:35:33 +0200 Subject: [PATCH] Translatre at init time --- pflaenzli/pflaenzli/forms.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pflaenzli/pflaenzli/forms.py b/pflaenzli/pflaenzli/forms.py index 93ca2e7..a64d31d 100644 --- a/pflaenzli/pflaenzli/forms.py +++ b/pflaenzli/pflaenzli/forms.py @@ -22,12 +22,23 @@ class RegistrationForm(UserCreationForm): class FilterForm(forms.Form): - text = forms.CharField(max_length=128, required=False, label=mark_safe( - f' {_("Search")}')) - zipcode = forms.CharField(max_length=4, required=False, label=mark_safe( - f' {_("ZIP code")}')) - distance = forms.IntegerField(required=False, label=mark_safe( - f' {_("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' {_("Search")}' + ) + self.fields['zipcode'].label = mark_safe( + f' {_("ZIP code")}' + ) + self.fields['distance'].label = mark_safe( + f' {_("Distance")} (km)' + ) class WishForm(forms.ModelForm):