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 Sarah Boyce, 7 months ago

Cc: Claude Paroz added
Component: UncategorizedInternationalization
Triage Stage: UnreviewedAccepted

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 👍

comment:2 by Vasyl Dizhak, 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.

Last edited 6 months ago by Vasyl Dizhak (previous) (diff)

comment:3 by Vasyl Dizhak, 6 months ago

Owner: changed from nobody to Vasyl Dizhak
Status: newassigned

comment:4 by Vasyl Dizhak, 6 months ago

Cc: Vasyl Dizhak added

comment:5 by viktorparipas92, 6 months ago

Cc: viktorparipas92 added

comment:6 by Claude Paroz, 4 months ago

Resolution: duplicate
Status: assignedclosed

Duplicate of #34221, as explained in comment:2, thanks Vasyl!

Note: See TracTickets for help on using tickets.
Back to Top