diff --git a/bin/addons/base/ir/ir_translation.py b/bin/addons/base/ir/ir_translation.py index 29c7ca308b4..631e42eb39b 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):