|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
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 $ |
19 | 19 |
|
20 | 20 | """ |
21 | 21 | RoundUp Internationalization (I18N) |
@@ -133,13 +133,28 @@ def get_translation(language=None, domain=DOMAIN, |
133 | 133 | try: |
134 | 134 | _fallback = find_translation(domain=domain, languages=["en"], |
135 | 135 | 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 |
136 | 148 | except IOError: |
137 | 149 | # no .mo files found |
138 | 150 | _fallback = None |
139 | 151 | # get the translation |
140 | 152 | try: |
141 | 153 | _translation = find_translation(domain=domain, languages=_languages, |
142 | 154 | class_=translation_class) |
| 155 | + # XXX See the comment after first find_translation() call |
| 156 | + if _translation.__class__ != translation_class: |
| 157 | + _translation.__class__ = translation_class |
143 | 158 | except IOError: |
144 | 159 | _translation = None |
145 | 160 | # see what's found |
|
0 commit comments