Browse Source

Fixed a bug when no compiled translations are available.

sh4nks 10 years ago
parent
commit
2c206df976
1 changed files with 6 additions and 3 deletions
  1. 6 3
      flaskbb/utils/translations.py

+ 6 - 3
flaskbb/utils/translations.py

@@ -1,6 +1,8 @@
 import os
 
 import babel
+from flask import _request_ctx_stack
+
 from flask_babelex import Domain, get_locale
 from flask_plugins import get_plugins_list
 
@@ -25,15 +27,16 @@ class FlaskBBDomain(Domain):
                 for plugin in get_plugins_list()
             ]
 
-    def get_translations_cache(self):
-        return self.cache
-
     def get_translations(self):
         """Returns the correct gettext translations that should be used for
         this request.  This will never fail and return a dummy translation
         object if used outside of the request or if a translation cannot be
         found.
         """
+        ctx = _request_ctx_stack.top
+        if ctx is None:
+            return babel.support.NullTranslations()
+
         locale = get_locale()
 
         cache = self.get_translations_cache()