#10903 closed defect (fixed)
Wrong `NullTranslations` class in functional tests
Reported by: | osimons | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.2 |
Component: | i18n | Version: | 1.0-stable |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Add support for Babel 1.0dev. |
||
API Changes: | |||
Internal Changes: |
Description
It seems that my derived use of functional test infrastructure in plugins now fails when testing against 1.0/trunk:
File "trac/util/translation.py", line 153, in activate t.add(Translations.load(locale_dir, locale or 'en_US', AttributeError: 'NullTranslations' object has no attribute 'add'
What seems to be the case is that t.__class__ is NullTranslations
is False
as the previously imported gettext.NullTranslations
does not resolve as equal to the actual babel.support.NullTranslations
of the t
variable. However, if I run tests without Babel installed it all works fine.
Hmm. Seems this follows from recent Babel 1.0dev changes, most specifically babel:changeset:650 I guess. Reverting to Babel 0.9.6 seems to solve the issue. However, the issue does not appear when testing against latest 0.12-stable so I guess it may also be connected to some other recent changes in for 1.0dev and later.
Here is a suggestion that should perhaps catch all variants:
-
trac/util/translation.py
a b try: 146 146 self._activate_failed = True 147 147 return 148 148 t = Translations.load(locale_dir, locale or 'en_US') 149 if not t or t.__class__ is NullTranslations:149 if not t or 'NullTranslations' in t.__class__.__name__: 150 150 t = self._null_translations 151 151 else: 152 152 t.add(Translations.load(locale_dir, locale or 'en_US',
Attachments (0)
Change History (10)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Ah, hadn't actually tested with the Trac tests - I was only running my plugin tests. Didn't know it was a problem in Trac too.
But yes, Trac trunk tests runs fine too with patch applied.
comment:3 by , 12 years ago
And without? I actually haven't verified that some Trac tests are failing with Babel 1.0dev (#10882 was an error within the web interface).
comment:4 by , 12 years ago
Tests fails without the patch.
Quickly skimming the Babel code I see that babel.support.NullTranslations
is supposed to be a subclass of gettext.NullTranslations
so there may well be more reliable ways of testing then just checking for the name NullTranslations
. Using isinstance()
is likely better and works too:
-
trac/util/translation.py
a b try: 146 146 self._activate_failed = True 147 147 return 148 148 t = Translations.load(locale_dir, locale or 'en_US') 149 if not t or t.__class__ is NullTranslations:149 if not t or isinstance(t, NullTranslations): 150 150 t = self._null_translations 151 151 else: 152 152 t.add(Translations.load(locale_dir, locale or 'en_US',
comment:5 by , 12 years ago
I've tried the patch in comment:4, however, Trac cannot translate messages with the patch. Because babel.support.Translations
class on babel trunk is a subclass of babel.support.NullTranslations
.
I think that the following would be simple and better.
-
trac/util/translation.py
146 146 self._activate_failed = True 147 147 return 148 148 t = Translations.load(locale_dir, locale or 'en_US') 149 if not t or t.__class__ is NullTranslations:149 if not isinstance(t, Translations): 150 150 t = self._null_translations 151 151 else: 152 152 t.add(Translations.load(locale_dir, locale or 'en_US',
comment:7 by , 12 years ago
Milestone: | → 1.0.2 |
---|---|
Owner: | set to |
Status: | new → assigned |
comment:8 by , 12 years ago
Owner: | changed from | to
---|
Jun, do you mind taking this one over? (applying your patch from comment:5)
I verified that with this patch and Babel 1.0dev (babel:changeset:fad20cd945e8/mirror) our tests pass. They also still pass with Babel 0.9.6 and without Babel.
comment:9 by , 12 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Oh, yes. I just work on it!
This issue occurs when compiled catalog file is missing for the locale, introduced in babel:r651.
$ find trac/locale -name '*.mo' -exec /bin/rm -- '{}' + # Remove all *.mo files $ make python=25-babel1.0 clean Trac.egg-info unit-test find -name \*.py[co] -exec rm {} \; rm -f .figleaf* *.figleaf ... File "/home/jun66j5/src/trac/edgewall/svn/branches/1.0-stable/trac/util/translation.py", line 152, in activate t.add(Translations.load(locale_dir, locale or 'en_US', AttributeError: 'NullTranslations' object has no attribute 'add' make: *** [unit-test] Error 1
Verified my patch with our tests:
- Babel 1.0dev-r661 with compiled catalogs and without catalogs
- Babel 0.9.6 with compiled catalogs and without catalogs
- Babel is not installed
Committed in [11783].
So this would fix #10882 as well?