浏览代码

fixes bugs about translations: #399 #400 #402 #403 #404 #405 (hopfully without breaking #173 again)

Damien Accorsi 7 年前
父节点
当前提交
3af2f58e85
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      tracim/tracim/lib/utils.py

+ 10 - 4
tracim/tracim/lib/utils.py 查看文件

@@ -3,6 +3,7 @@ import os
3 3
 import time
4 4
 import signal
5 5
 
6
+import tg
6 7
 from tg import config
7 8
 from tg import require
8 9
 from tg import response
@@ -150,12 +151,17 @@ def _lazy_ugettext(text: str):
150 151
     :return: lazyfied string or string
151 152
     """
152 153
     try:
153
-        # Test if context is available,
154
+        # Test if tg.translator is defined
155
+        #
154 156
         # cf. https://github.com/tracim/tracim/issues/173
155
-        context = StackedObjectProxy(name="context")
156
-        context.translator
157
+        #
158
+        # HACK - 2017-11-03 - D.A
159
+        # Replace context proxyfied by direct access to gettext function
160
+        # which is not setup in case the tg2 context is not initialized
161
+        tg.translator.gettext  # raises a TypeError exception if context not set
157 162
         return ugettext(text)
158
-    except TypeError:
163
+    except TypeError as e:
164
+        logger.debug(_lazy_ugettext, 'TG2 context not available for translation. TypeError: {}'.format(e))
159 165
         return text
160 166
 
161 167
 lazy_ugettext = lazify(_lazy_ugettext)