-
Issue Select2Mixin is only initialized on (development) server start this way: def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.i18n_name = SELECT2_TRANSLATIONS.get(get_language())
But the current language might change on a request basis, for example due to
The @property
def media(self):
... code removed for brevity ...
i18n_file = []
if self.i18n_name in settings.SELECT2_I18N_AVAILABLE_LANGUAGES:
i18n_file = [f"{settings.SELECT2_I18N_PATH}/{self.i18n_name}.js"] This will prevent the select2-based controls from translating correctly. No amount of effort (e.g. setting data-language or lang in the attrs for a control) can fix this, as you would also be required to resolve the JS file name externally and swap it with the incorrect one being supplied by the media method. Expected behavior django-select2 should check the current active translation before building the media information and also before build_attrs |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @arneatec thank you for reaching out. I sincerely appreciate your detailed report. Would you be so kind as to explain how exactly you are experiencing this problem? Your deduction is interesting, but Django handles languages actually slightly different from what you describe. Django uses thread locals and the locale middleware will set the variable. As it happens, I implemented the same language behavior for select2 in Django itself for autocomplete fields, so I am fairly confident about the implementation. But I'm known to make mistakes 😜 However, let's try to troubleshoot this together. Some issues I could think of would be that the language isn't properly set OR some kind of state leakage. It would help you have some browser logs, that include the request headers and cookies. I hope we can figure this out! Best, |
Beta Was this translation helpful? Give feedback.
-
Hi @codingjoe Simplified code is here https://github.com/arneatec/django-select2-locale.git I've used Bulgarian (bg) as test language. Model field names are translated to Bulgarian (with the English captions put in parentheses after the translation for your convenience). I'm using pycharm with runserver. Requirements file shows there are no other fancy dependencies that might be interfering, I've tried to make this as generic as possible. Issue is reproducible in the example code. Steps to reproduce:
Workaround/temporary fix: Please let me know if I can be of further help. Regards, |
Beta Was this translation helpful? Give feedback.
Hi @codingjoe
Simplified code is here https://github.com/arneatec/django-select2-locale.git
I've used Bulgarian (bg) as test language. Model field names are translated to Bulgarian (with the English captions put in parentheses after the translation for your convenience).
I'm using pycharm with runserver. Requirements file shows there are no other fancy dependencies that might be interfering, I've tried to make this as generic as possible.
Issue is reproducible in the example code.
Steps to reproduce: