#33070: Select2 doesn't load translations with subtags.
---------------------------------+-------------------------------------
     Reporter:  Cleiton de Lima  |                    Owner:  sarath ak
         Type:  Bug              |                   Status:  new
    Component:  contrib.admin    |                  Version:  3.2
     Severity:  Normal           |               Resolution:
     Keywords:  select2          |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+-------------------------------------

Comment (by Cleiton de Lima):

 It looks good to me too!

 Replying to [comment:5 Mariusz Felisiak]:
 > Replying to [comment:4 Cleiton de Lima]:
 > > Replying to [comment:3 Mariusz Felisiak]:
 > > > `LANGUAGE_CODE` should be lowercased, so `pt-br` instead of `pt-BR`,
 see [https://docs.djangoproject.com/en/3.2/topics/i18n/#definitions
 "Definitions"], [https://docs.djangoproject.com/en/3.2/ref/settings
 /#language-code LANGUAGE_CODE docs], and the list of
 
[https://github.com/django/django/blob/3219dd3388c437b4bd869b76ddd43c9cdad05090/django/conf/global_settings.py#L124
 LANGUAGES].
 > >
 > > The translation of select2 only accepts pt-BR that way.
 > > The file is found but the translation doesn't work. It only works when
 the tag html has
 > > {{{<html lang="pt-BR" dir="ltr" data-select2-id="14">...}}}
 > >
 >
 > Thanks, I didn't notice that `Select2` loads translations based on
 `LANG`. Lowercase when searching for a file will help only for `pt-BR` but
 not for `zh-hans`, `pt-br` etc. We could probably add `lang` to the
 `attrs`, e.g.:
 > {{{
 > diff --git a/django/contrib/admin/widgets.py
 b/django/contrib/admin/widgets.py
 > index aeb74773ac..f1002cac6c 100644
 > --- a/django/contrib/admin/widgets.py
 > +++ b/django/contrib/admin/widgets.py
 > @@ -388,6 +388,7 @@ class AutocompleteMixin:
 >          self.db = using
 >          self.choices = choices
 >          self.attrs = {} if attrs is None else attrs.copy()
 > +        self.i18n_name = SELECT2_TRANSLATIONS.get(get_language())
 >
 >      def get_url(self):
 >          return reverse(self.url_name % self.admin_site.name)
 > @@ -413,6 +414,7 @@ class AutocompleteMixin:
 >              'data-theme': 'admin-autocomplete',
 >              'data-allow-clear': json.dumps(not self.is_required),
 >              'data-placeholder': '',  # Allows clearing of the input.
 > +            'lang': self.i18n_name,
 >              'class': attrs['class'] + (' ' if attrs['class'] else '') +
 'admin-autocomplete',
 >          })
 >          return attrs
 > @@ -449,8 +451,7 @@ class AutocompleteMixin:
 >      @property
 >      def media(self):
 >          extra = '' if settings.DEBUG else '.min'
 > -        i18n_name = SELECT2_TRANSLATIONS.get(get_language())
 > -        i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % i18n_name,)
 if i18n_name else ()
 > +        i18n_file = ('admin/js/vendor/select2/i18n/%s.js' %
 self.i18n_name,) if self.i18n_name else ()
 >          return forms.Media(
 >              js=(
 >                  'admin/js/vendor/jquery/jquery%s.js' % extra,
 > }}}
 > What do you think? It works for me.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.2b42edbbfbefedbe8161c9acbca309b4%40djangoproject.com.

Reply via email to