From 95ccad32c216b71b4f3188da0f6b82d2128a90c2 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Sat, 5 Nov 2022 11:50:59 +0100 Subject: [PATCH] Fix #163 -- Lazily get i18n locale name A widget instance can leak the i18n setting to another request or be stuck on the default language setting. --- django_select2/forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_select2/forms.py b/django_select2/forms.py index df3982fe..8c046b50 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -86,9 +86,10 @@ class Select2Mixin: empty_label = "" - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.i18n_name = SELECT2_TRANSLATIONS.get(get_language()) + @property + def i18n_name(self): + """The name of the i18n file for the current language.""" + return SELECT2_TRANSLATIONS.get(get_language()) def build_attrs(self, base_attrs, extra_attrs=None): """Add select2 data attributes."""