Browse Source

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

Damien Accorsi 7 years ago
parent
commit
3af2f58e85
1 changed files with 10 additions and 4 deletions
  1. 10 4
      tracim/tracim/lib/utils.py

+ 10 - 4
tracim/tracim/lib/utils.py View File

3
 import time
3
 import time
4
 import signal
4
 import signal
5
 
5
 
6
+import tg
6
 from tg import config
7
 from tg import config
7
 from tg import require
8
 from tg import require
8
 from tg import response
9
 from tg import response
150
     :return: lazyfied string or string
151
     :return: lazyfied string or string
151
     """
152
     """
152
     try:
153
     try:
153
-        # Test if context is available,
154
+        # Test if tg.translator is defined
155
+        #
154
         # cf. https://github.com/tracim/tracim/issues/173
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
         return ugettext(text)
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
         return text
165
         return text
160
 
166
 
161
 lazy_ugettext = lazify(_lazy_ugettext)
167
 lazy_ugettext = lazify(_lazy_ugettext)