#34221: Plural-Forms in .po files break Django's translation precedence.
--------------------------------------+------------------------------------
     Reporter:  Stefano Parmesan      |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  Internationalization  |                  Version:  4.1
     Severity:  Normal                |               Resolution:
     Keywords:  i18n                  |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the detailed report and test project!

 To solve #30439 and allow for different plural forms for a same language,
 we had to refrain from merging all translations in a unique catalog, as
 was done before. However, your setup demonstrates that the algorithm to
 decide between merge or separating catalogs is flawed (the third catalog
 from LOCALE_PATH having the same plural forms as the Django one, it is
 merge with it, hence loosing it's priority over the intermediary django-
 extension catalog).

 The following patch should fix the issue:
 {{{
 diff --git a/django/utils/translation/trans_real.py
 b/django/utils/translation/trans_real.py
 index c1e64d4ebd..f4d05b8f76 100644
 --- a/django/utils/translation/trans_real.py
 +++ b/django/utils/translation/trans_real.py
 @@ -96,11 +96,9 @@ class TranslationCatalog:
              yield from cat.keys()

      def update(self, trans):
 -        # Merge if plural function is the same, else prepend.
 -        for cat, plural in zip(self._catalogs, self._plurals):
 -            if trans.plural.__code__ == plural.__code__:
 -                cat.update(trans._catalog)
 -                break
 +        # Merge if plural function is the same as the top catalog, else
 prepend.
 +        if trans.plural.__code__ == self._plurals[0]:
 +            self._catalogs[0].update(trans._catalog)
          else:
              self._catalogs.insert(0, trans._catalog.copy())
              self._plurals.insert(0, trans.plural)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34221#comment:2>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070185363fabc7-2312c96f-b0a6-4726-b325-42819db5af9b-000000%40eu-central-1.amazonses.com.

Reply via email to