Skip to content

Commit f97e2fd

Browse files
author
Alexander Smishlajev
committed
work around invalid class returned from gettext.translation()
1 parent b0eda4a commit f97e2fd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

roundup/i18n.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: i18n.py,v 1.9 2004-07-11 14:16:26 a1s Exp $
18+
# $Id: i18n.py,v 1.10 2004-07-14 07:27:21 a1s Exp $
1919

2020
"""
2121
RoundUp Internationalization (I18N)
@@ -133,13 +133,28 @@ def get_translation(language=None, domain=DOMAIN,
133133
try:
134134
_fallback = find_translation(domain=domain, languages=["en"],
135135
class_=translation_class)
136+
# gettext.translation returns a cached translation
137+
# even if it is not of the desired class.
138+
# This is a quick-and-dirty solution for this problem.
139+
# It works with current codebase, because all translators
140+
# inherit from respective base translation classes
141+
# defined in the gettext module, i.e. have same internal data.
142+
# The cached instance is not affected by this hack,
143+
# 'cause gettext made a copy for us.
144+
# XXX Consider making a copy of gettext.translation function
145+
# with class bug fixed...
146+
if _fallback.__class__ != translation_class:
147+
_fallback.__class__ = translation_class
136148
except IOError:
137149
# no .mo files found
138150
_fallback = None
139151
# get the translation
140152
try:
141153
_translation = find_translation(domain=domain, languages=_languages,
142154
class_=translation_class)
155+
# XXX See the comment after first find_translation() call
156+
if _translation.__class__ != translation_class:
157+
_translation.__class__ = translation_class
143158
except IOError:
144159
_translation = None
145160
# see what's found

0 commit comments

Comments
 (0)