Skip to content

Commit 05a2af3

Browse files
committed
Do not throw an internal error if a .mo file can not be read
It is better to fall back to English (as already done in other situations) than causing an internal server error.
1 parent 9b6cf96 commit 05a2af3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Fixed:
2222
(anatoly techtonik)
2323
- Read version and release for generated documentation from
2424
roundup/__init__.py. (Thomas Arendsen Hein)
25+
- Do not throw an internal error if a .mo file can not be read
26+
(Thomas Arendsen Hein)
2527

2628

2729
2013-07-06: 1.5.0

roundup/i18n.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,20 @@ def get_translation(language=None, tracker_home=None,
181181
mofiles.append(get_mofile(locales, system_locale, DOMAIN))
182182
# filter out elements that are not found
183183
mofiles = filter(None, mofiles)
184-
if mofiles:
185-
translator = translation_class(open(mofiles[0], "rb"))
186-
for mofile in mofiles[1:]:
187-
# note: current implementation of gettext_module
188-
# always adds fallback to the end of the fallback chain.
189-
translator.add_fallback(translation_class(open(mofile, "rb")))
190-
else:
184+
translator = None
185+
for mofile in mofiles:
186+
try:
187+
mo = open(mofile, "rb")
188+
if translator is None:
189+
translator = translation_class(mo)
190+
else:
191+
# note: current implementation of gettext_module
192+
# always adds fallback to the end of the fallback chain.
193+
translator.add_fallback(translation_class(mo))
194+
except IOError:
195+
# ignore unreadable .mo files
196+
pass
197+
if translator is None:
191198
translator = null_translation_class()
192199
return translator
193200

0 commit comments

Comments
 (0)