Opened 7 months ago
Closed 4 months ago
#35476 closed Bug (duplicate)
The precedence of multiple translations for the same literal does not work on Python3.11 & Python3.12
Reported by: | Dmytro Litvinov | Owned by: | Vasyl Dizhak |
---|---|---|---|
Component: | Internationalization | Version: | 4.2 |
Severity: | Normal | Keywords: | i18n, translation |
Cc: | Dmytro Litvinov, Claude Paroz, Vasyl Dizhak, viktorparipas92 | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
According to documentation https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#how-django-discovers-translations
Django will look for translations in the following order:
- LOCALE_PATHS directories
- 3rd party apps
- django/conf/locale
I created example project with reproducing the issue at GitHub - https://github.com/DmytroLitvinov/django-i18n-issue
As for Python3.10 it works according to documentation, but if we start to use Python3.11 and higher (like Python3.12) - we will see that the order is not correct and it will take first from 3rd party app (like in my example from django-allauth library).
To confirm that translation in LOCALE_PATHS are working correctly, we can comment out 'allauth' in INSTALLED_APPS settings and see that translation of word 'Continue' will be correctly taken from LOCALE_PATHS folders.
Change History (6)
comment:1 by , 7 months ago
Cc: | added |
---|---|
Component: | Uncategorized → Internationalization |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 months ago
We've (together with @viktorparipas92) been working on this issue during the Sprints after the DjangoCon Europe 2024 and this issue is related to #34221 as we can link it with the same wrong behavior when comparing the plural functions.
Django uses the following plural function
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
which matches exactly with the one from the demo repository https://github.com/DmytroLitvinov/django-i18n-issue/blob/main/locale/de/LC_MESSAGES/django.po#L19C28-L19C43, therefore, local translations will be merged into the first catalog together with Django's translations.
The allauth
package has a different plural function that would insert it in the first position in the translation catalog https://github.com/pennersr/django-allauth/blob/main/allauth/locale/de/LC_MESSAGES/django.po#L20
"Plural-Forms: nplurals=2; plural=n != 1;\n"
gettext
would check first the 3d-party allauth
translations catalog as it has higher precedence, and only then look at the merged one containing the local files.
We propose to close it as a duplicate to the #34221.
comment:3 by , 6 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 6 months ago
Cc: | added |
---|
comment:5 by , 6 months ago
Cc: | added |
---|
comment:6 by , 4 months ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Thank you for the report and the test project! Replicated and confirmed this works on using Python 3.10
This appears to be a different issue to #34221 👍