Skip to content

Commit

Permalink
Fix #163 -- Lazily get i18n locale name
Browse files Browse the repository at this point in the history
A widget instance can leak the i18n setting to another request
or be stuck on the default language setting.
  • Loading branch information
codingjoe committed Nov 5, 2022
1 parent 5894b52 commit 95ccad3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 95ccad3

Please sign in to comment.