#31570: Translations of one language in different territories can override each
other
--------------------------------------+------------------------------------
Reporter: Shai Berger | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 2.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Shai Berger):
Replying to [comment:11 Claude Paroz]:
> [...] plural function comparison broken. [...] If it worked, this bug
wouldn't have surface in this use case
After further investigation: This claim is technically correct, but is not
helpful for solving this bug.
To my surprise, I found that there are actually two different
implementations of the plural function in the English translation files.
From the apps in the default project template, {{{admin}}} and {{{auth}}}
have
{{{
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
}}}
but this line is not found in the {{{en}}} translations (which exist) for
{{{contenttypes}}} and {{{sessions}}}, nor in the files initially
generated by {{{makemessages}}}. The {{{__code__}}} comparison considers
the default different from the explicit plural equation, but otherwise
works.
Now, given that the default plural function is {{{lambda n: int(n !=
1)}}}, it is indeed the case that if the plural function comparison worked
perfectly, all the plural functions involved would have been considered
equal, and the problem would not arise.
However, the point of #30439 was exactly the support of files with
different plural-functions for the same language. So the effect of the
comparison failure is just to allow us to debug with English, a problem
which could pop up in another language, where different functions are more
common.
As an aside, this was the major missing piece which allowed me to
reproduce exactly the behavior I saw in production: Adding the explicit
plural forms to my apps' translation files, and making the test run two
rounds of translations (as only when the first round ends, all languages
are loaded), that is
{{{#!diff
*** trans/tests.py~ 2020-05-13 12:38:30.028586931 +0300
--- trans/tests.py 2020-05-15 16:32:14.537889998 +0300
*************** class TestTranslations(SimpleTestCase):
*** 10,17 ****
'en_CA': 'canuck',
'en': 'local country person',
}
! for language, nick in country_people_nicknames.items():
! with self.subTest(language=language):
activate(language)
self.assertEqual(_('local country person'), nick)
--- 10,18 ----
'en_CA': 'canuck',
'en': 'local country person',
}
! for rnd in "12":
! for language, nick in country_people_nicknames.items():
! with self.subTest(language=language, round=rnd):
activate(language)
self.assertEqual(_('local country person'), nick)
}}}
Allowed me to get as output
{{{
======================================================================
FAIL: test_region_translations (trans.tests.TestTranslations)
(language='en', round='1')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/slate/tmp/test_31570/trans/tests.py", line 17, in
test_region_translations
self.assertEqual(_('local country person'), nick)
AssertionError: 'canuck' != 'local country person'
- canuck
+ local country person
======================================================================
FAIL: test_region_translations (trans.tests.TestTranslations)
(language='en_NZ', round='2')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/slate/tmp/test_31570/trans/tests.py", line 17, in
test_region_translations
self.assertEqual(_('local country person'), nick)
AssertionError: 'canuck' != 'kiwi'
- canuck
+ kiwi
======================================================================
FAIL: test_region_translations (trans.tests.TestTranslations)
(language='en', round='2')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/slate/tmp/test_31570/trans/tests.py", line 17, in
test_region_translations
self.assertEqual(_('local country person'), nick)
AssertionError: 'canuck' != 'local country person'
- canuck
+ local country person
}}}
That is, the {{{en-nz}}} (and {{{en}}}) dialect was overridden by {{{en-
ca}}}.
--
Ticket URL: <https://code.djangoproject.com/ticket/31570#comment:15>
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/063.a20b7134b30574154960f04e06c149b8%40djangoproject.com.