[Kimchi-devel] [PATCH] [Wok 1/4] Add option to get untranslated message text

Lucio Correia luciojhc at linux.vnet.ibm.com
Thu Aug 4 18:15:23 UTC 2016


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 src/wok/message.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/wok/message.py b/src/wok/message.py
index 4c35747..35f40be 100644
--- a/src/wok/message.py
+++ b/src/wok/message.py
@@ -46,7 +46,7 @@ class WokMessage(object):
         self.args = args
         self.plugin = plugin
 
-    def _get_translation(self):
+    def _get_text(self, translate):
         wok_app = cherrypy.tree.apps.get('', None)
 
         # get app from plugin path if specified
@@ -68,20 +68,23 @@ class WokMessage(object):
             app = wok_app
             text = app.root.messages.get(self.code, self.code)
 
-        # do translation
-        domain = app.root.domain
-        paths = app.root.paths
-        lang = validate_language(get_lang())
+        if translate:
+            # do translation
+            domain = app.root.domain
+            paths = app.root.paths
+            lang = validate_language(get_lang())
 
-        try:
-            translation = gettext.translation(domain, paths.mo_dir, [lang])
-        except:
-            translation = gettext
+            try:
+                translation = gettext.translation(domain, paths.mo_dir, [lang])
+            except:
+                translation = gettext
+
+            return translation.gettext(text)
 
-        return translation.gettext(text)
+        return gettext.gettext(text)
 
-    def get_text(self, prepend_code=True):
-        msg = self._get_translation()
+    def get_text(self, prepend_code=True, translate=True):
+        msg = self._get_text(translate)
         msg = unicode(msg, 'utf-8') % self.args
 
         if prepend_code:
-- 
1.9.1




More information about the Kimchi-devel mailing list