From: Olivier Dony Date: Wed, 8 Sep 2010 17:04:09 +0000 (+0200) Subject: [FIX] ir.translation: ensure consistent return type for _get_source(), pending proper fix X-Git-Tag: 6.0.0-rc1-server~159^2~74 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=ac2ea17fab7be0117439baceb41aec56dd602678;p=odoo%2Fodoo.git [FIX] ir.translation: ensure consistent return type for _get_source(), pending proper fix lp bug: https://launchpad.net/bugs/613721 fixed bzr revid: odo@openerp.com-20100908170409-3k7tfolwgn599334 --- diff --git a/bin/addons/base/ir/ir_translation.py b/bin/addons/base/ir/ir_translation.py index 29c7ca3..631e42e 100644 --- a/bin/addons/base/ir/ir_translation.py +++ b/bin/addons/base/ir/ir_translation.py @@ -132,11 +132,25 @@ class ir_translation(osv.osv): @tools.cache(skiparg=3) def _get_source(self, cr, uid, name, tt, lang, source=None): + """ + Returns the translation for the given combination of name, type, language + and source. All values passed to this method should be unicode (not byte strings), + especially ``source``. + + :param name: identification of the term to translate, such as field name + :param type: type of term to translate (see ``type`` field on ir.translation) + :param lang: language code of the desired translation + :param source: optional source term to translate (should be unicode) + :rtype: unicode + :return: the request translation, or an empty unicode string if no translation was + found and `source` was not passed + """ + # FIXME: should assert that `source` is unicode and fix all callers to always pass unicode + # so we can remove the string encoding/decoding. + if not lang: - return '' + return u'' if source: - #if isinstance(source, unicode): - # source = source.encode('utf8') cr.execute('select value ' \ 'from ir_translation ' \ 'where lang=%s ' \ @@ -152,9 +166,9 @@ class ir_translation(osv.osv): 'and name=%s', (lang or '', tt, tools.ustr(name))) res = cr.fetchone() - trad = res and res[0] or '' + trad = res and res[0] or u'' if source and not trad: - return source + return tools.ustr(source) return trad def create(self, cursor, user, vals, context=None):