changeset 4838:6102252d3a8a

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.
author Thomas Arendsen Hein <thomas@intevation.de>
date Wed, 02 Oct 2013 15:36:34 +0200
parents bf786562ba7f
children c317147fd891
files CHANGES.txt roundup/i18n.py
diffstat 2 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Sep 25 15:35:11 2013 +0300
+++ b/CHANGES.txt	Wed Oct 02 15:36:34 2013 +0200
@@ -22,6 +22,8 @@
   (anatoly techtonik)
 - Read version and release for generated documentation from
   roundup/__init__.py. (Thomas Arendsen Hein)
+- Do not throw an internal error if a .mo file can not be read
+  (Thomas Arendsen Hein)
 
 
 2013-07-06: 1.5.0
--- a/roundup/i18n.py	Wed Sep 25 15:35:11 2013 +0300
+++ b/roundup/i18n.py	Wed Oct 02 15:36:34 2013 +0200
@@ -181,13 +181,20 @@
             mofiles.append(get_mofile(locales, system_locale, DOMAIN))
     # filter out elements that are not found
     mofiles = filter(None, mofiles)
-    if mofiles:
-        translator = translation_class(open(mofiles[0], "rb"))
-        for mofile in mofiles[1:]:
-            # note: current implementation of gettext_module
-            #   always adds fallback to the end of the fallback chain.
-            translator.add_fallback(translation_class(open(mofile, "rb")))
-    else:
+    translator = None
+    for mofile in mofiles:
+        try:
+            mo = open(mofile, "rb")
+            if translator is None:
+                translator = translation_class(mo)
+            else:
+                # note: current implementation of gettext_module
+                #   always adds fallback to the end of the fallback chain.
+                translator.add_fallback(translation_class(mo))
+        except IOError:
+            # ignore unreadable .mo files
+            pass
+    if translator is None:
         translator = null_translation_class()
     return translator
 

Roundup Issue Tracker: http://roundup-tracker.org/