[Django] #33070: Error using select2 translation files

64 views
Skip to first unread message

Django

unread,
Aug 30, 2021, 9:09:13 AM8/30/21
to django-...@googlegroups.com
#33070: Error using select2 translation files
-------------------------------------------+-------------------------
Reporter: Cleiton de Lima | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Keywords: select2
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------------+-------------------------
For example, when using the setting {{{LANGUAGE_CODE="pt-BR"}}}, the
translation of select2 is not applied, the static file i18n is not found.
This is due to the fact that some languages are converted to lowercase.
https://github.com/django/django/blob/main/django/contrib/admin/widgets.py#L366

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

Django

unread,
Aug 30, 2021, 1:35:36 PM8/30/21
to django-...@googlegroups.com
#33070: Error using select2 translation files
---------------------------------+--------------------------------------
Reporter: Cleiton de Lima | Owner: sarath ak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: select2 | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by sarath ak):

* owner: nobody => sarath ak
* status: new => assigned


Comment:

I fixed it

https://github.com/django/django/pull/14813

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:1>

Django

unread,
Aug 30, 2021, 1:43:40 PM8/30/21
to django-...@googlegroups.com
#33070: Error using select2 translation files
---------------------------------+--------------------------------------
Reporter: Cleiton de Lima | Owner: sarath ak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: select2 | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by sarath ak):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:2>

Django

unread,
Aug 30, 2021, 2:00:21 PM8/30/21
to django-...@googlegroups.com
#33070: Error using select2 translation files
---------------------------------+--------------------------------------
Reporter: Cleiton de Lima | Owner: sarath ak
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: select2 | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* has_patch: 1 => 0
* resolution: => invalid


Comment:

`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].

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:3>

Django

unread,
Aug 30, 2021, 2:57:09 PM8/30/21
to django-...@googlegroups.com
#33070: Error using select2 translation files
---------------------------------+--------------------------------------
Reporter: Cleiton de Lima | Owner: sarath ak
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: select2 | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by 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.
https://github.com/django/django/blob/main/django/contrib/admin/static/admin/js/vendor/select2/i18n
/pt-BR.js

https://github.com/django/django/blob/main/django/contrib/admin/widgets.py#L453

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:4>

Django

unread,
Aug 31, 2021, 12:58:46 AM8/31/21
to django-...@googlegroups.com
#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
---------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: closed => new
* cc: info@… (removed)
* cc: Johannes Maron, Claude Paroz (added)
* easy: 1 => 0
* resolution: invalid =>
* stage: Unreviewed => Accepted


Comment:

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:5>

Django

unread,
Sep 20, 2021, 12:57:11 PM9/20/21
to django-...@googlegroups.com
#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]:

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:6>

Django

unread,
Sep 20, 2021, 1:04:36 PM9/20/21
to django-...@googlegroups.com
#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
---------------------------------+-------------------------------------
Changes (by Cleiton de Lima):

* cc: Cleiton de Lima (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:7>

Django

unread,
Sep 20, 2021, 1:56:45 PM9/20/21
to django-...@googlegroups.com
#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 Mariusz Felisiak):

Cleiton, thanks for checking. Would you like to prepare a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:8>

Django

unread,
Sep 20, 2021, 2:29:36 PM9/20/21
to django-...@googlegroups.com
#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):

Yes, I will.

Replying to [comment:8 Mariusz Felisiak]:


> Cleiton, thanks for checking. Would you like to prepare a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:9>

Django

unread,
Sep 20, 2021, 2:36:14 PM9/20/21
to django-...@googlegroups.com
#33070: Select2 doesn't load translations with subtags.
-------------------------------------+-------------------------------------
Reporter: Cleiton de Lima | Owner: Cleiton
| de Lima
Type: Bug | Status: assigned
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
-------------------------------------+-------------------------------------

Changes (by Cleiton de Lima):

* owner: sarath ak => Cleiton de Lima


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:10>

Django

unread,
Sep 20, 2021, 3:58:40 PM9/20/21
to django-...@googlegroups.com
#33070: Select2 doesn't load translations with subtags.
-------------------------------------+-------------------------------------
Reporter: Cleiton de Lima | Owner: Cleiton
| de Lima
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Normal | Resolution:
Keywords: select2 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14871 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:11>

Django

unread,
Sep 21, 2021, 1:25:20 AM9/21/21
to django-...@googlegroups.com
#33070: Select2 doesn't load translations with subtags.
-------------------------------------+-------------------------------------
Reporter: Cleiton de Lima | Owner: Cleiton
| de Lima
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: select2 | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:12>

Django

unread,
Sep 21, 2021, 2:08:05 AM9/21/21
to django-...@googlegroups.com
#33070: Select2 doesn't load translations with subtags.
-------------------------------------+-------------------------------------
Reporter: Cleiton de Lima | Owner: Cleiton
| de Lima
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: select2 | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed

* resolution: => fixed


Comment:

In [changeset:"8eb56930915f8022aa27ec29ab5be7d21764608c" 8eb56930]:
{{{
#!CommitTicketReference repository=""
revision="8eb56930915f8022aa27ec29ab5be7d21764608c"
Fixed #33070 -- Fixed loading translations with language subtags in
admin's Select2 widget.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:13>

Django

unread,
Sep 21, 2021, 2:08:34 AM9/21/21
to django-...@googlegroups.com
#33070: Select2 doesn't load translations with subtags.
-------------------------------------+-------------------------------------
Reporter: Cleiton de Lima | Owner: Cleiton
| de Lima
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2

Severity: Normal | Resolution: fixed
Keywords: select2 | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"a077f10df477880a23faad333aae8d9ef8738152" a077f10]:
{{{
#!CommitTicketReference repository=""
revision="a077f10df477880a23faad333aae8d9ef8738152"
[4.0.x] Fixed #33070 -- Fixed loading translations with language subtags


in admin's Select2 widget.

Backport of 8eb56930915f8022aa27ec29ab5be7d21764608c from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33070#comment:14>

Reply all
Reply to author
Forward
0 new messages