From 4e80903f940f8d7ff109b241504ddbb6c4bcfd2a Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 15 Jul 2008 10:40:23 +0200 Subject: [PATCH] now _() works ! but bzr... bzr revid: christophe@tinyerp.com-20080715084023-tzhwid7be6r8067u --- bin/tools/translate.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/tools/translate.py b/bin/tools/translate.py index fa230e7241e..e38c0f203b1 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -34,7 +34,7 @@ import osv, tools, pooler import ir import netsvc from tools.misc import UpdateableStr - +import inspect class UNIX_LINE_TERMINATOR(csv.excel): lineterminator = '\n' @@ -55,13 +55,17 @@ def translate(cr, name, source_type, lang, source=None): res = res_trans and res_trans[0] or False return res -def translate_code(cr, source, context): - lang = context.get('lang', False) - if lang: - return translate(cr, None, 'code', lang, source) or source - else: - return source -_ = lambda source: translate_code(cr, source, context) +class GettextAlias(object): + def __call__(self, source): + frame = inspect.stack()[1][0] + cr = frame.f_locals['cr'] + context = frame.f_locals.get('context', {}) + lang = context.get('lang', False) + if not lang: + return source + return translate(cr, None, 'code', lang, source) or source + +_ = GettextAlias() # Methods to export the translation file