From ff55f829ce88153dc54ba6f50323e43224662a69 Mon Sep 17 00:00:00 2001 From: OpenERP Date: Fri, 17 Dec 2010 13:38:22 +0100 Subject: [PATCH 1/2] [FIX] translate: correctly set the translation for menus indirectly named by their action and not visible in the simplified view. bzr revid: openerp@vmt-hp4520s-20101217123822-0g5h04fz92fxfn42 --- bin/tools/translate.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/tools/translate.py b/bin/tools/translate.py index 76d41d25054..a296f0e445d 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -933,7 +933,11 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= if obj: if field not in obj.fields_get_keys(cr, uid): continue - ids = obj.search(cr, uid, [(field, '=', dic['src'])]) + # Using search() instead of _search() will limit the + # returned list to the ids visible to uid, which is not + # in the extended view group. We want all of them and use + # _search(). + ids = obj._search(cr, uid, [(field, '=', dic['src'])]) # if the resource id (res_id) is in that list, use it, # otherwise use the whole list From edcbf91f032a18af4b3e11633a831194897f6804 Mon Sep 17 00:00:00 2001 From: OpenERP Date: Mon, 20 Dec 2010 16:15:23 +0100 Subject: [PATCH 2/2] [FIX] orm, translate: unconditionally set the translation from .pot to db, lookup a translation by name, type, and lang only (no more source string) lp bug: https://launchpad.net/bugs/682092 fixed bzr revid: openerp@vmt-hp4520s-20101220151523-vy4xzvahz80tara7 --- bin/osv/orm.py | 2 +- bin/tools/translate.py | 61 ++++++++++-------------------------------- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index a652ad54f04..73c91657d8c 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1237,7 +1237,7 @@ class orm_template(object): res[f][arg] = getattr(field_col, arg) if field_col.string: - res_trans = translation_obj._get_source(cr, user, self._name + ',' + f, 'field', context.get('lang', False) or 'en_US', field_col.string) + res_trans = translation_obj._get_source(cr, user, self._name + ',' + f, 'field', context.get('lang', False) or 'en_US') if res_trans: res[f]['string'] = res_trans if field_col.help: diff --git a/bin/tools/translate.py b/bin/tools/translate.py index a296f0e445d..ff4dd4e3d9b 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -808,13 +808,13 @@ def trans_generate(lang, modules, dbname=None): cr.close() return out -def trans_load(db_name, filename, lang, strict=False, verbose=True, context=None): +def trans_load(db_name, filename, lang, verbose=True, context=None): logger = logging.getLogger('i18n') try: fileobj = open(filename,'r') logger.info("loading %s", filename) fileformat = os.path.splitext(filename)[-1][1:].lower() - r = trans_load_data(db_name, fileobj, fileformat, lang, strict=strict, verbose=verbose, context=context) + r = trans_load_data(db_name, fileobj, fileformat, lang, verbose=verbose, context=context) fileobj.close() return r except IOError: @@ -822,7 +822,7 @@ def trans_load(db_name, filename, lang, strict=False, verbose=True, context=None logger.error("couldn't read translation file %s", filename) return None -def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=None, verbose=True, context=None): +def trans_load_data(db_name, fileobj, fileformat, lang, lang_name=None, verbose=True, context=None): logger = logging.getLogger('i18n') if verbose: logger.info('loading translation file for language %s', lang) @@ -924,52 +924,19 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= else: dic['res_id'] = False - if dic['type'] == 'model' and not strict: - (model, field) = dic['name'].split(',') + args = [ + ('lang', '=', lang), + ('type', '=', dic['type']), + ('name', '=', dic['name']) + ] + if dic['type'] == 'model': + args.append(('res_id', '=', dic['res_id'])) - # get the ids of the resources of this model which share - # the same source - obj = pool.get(model) - if obj: - if field not in obj.fields_get_keys(cr, uid): - continue - # Using search() instead of _search() will limit the - # returned list to the ids visible to uid, which is not - # in the extended view group. We want all of them and use - # _search(). - ids = obj._search(cr, uid, [(field, '=', dic['src'])]) - - # if the resource id (res_id) is in that list, use it, - # otherwise use the whole list - if not ids: - ids = [] - ids = (dic['res_id'] in ids) and [dic['res_id']] or ids - for id in ids: - dic['res_id'] = id - ids = trans_obj.search(cr, uid, [ - ('lang', '=', lang), - ('type', '=', dic['type']), - ('name', '=', dic['name']), - ('src', '=', dic['src']), - ('res_id', '=', dic['res_id']) - ]) - if ids: - if context.get('overwrite', False): - trans_obj.write(cr, uid, ids, {'value': dic['value']}) - else: - trans_obj.create(cr, uid, dic) + ids = trans_obj.search(cr, uid, args) + if ids and context.get('overwrite', False): + trans_obj.write(cr, uid, ids, {'value': dic['value']}) else: - ids = trans_obj.search(cr, uid, [ - ('lang', '=', lang), - ('type', '=', dic['type']), - ('name', '=', dic['name']), - ('src', '=', dic['src']) - ]) - if ids: - if context.get('overwrite', False): - trans_obj.write(cr, uid, ids, {'value': dic['value']}) - else: - trans_obj.create(cr, uid, dic) + trans_obj.create(cr, uid, dic) cr.commit() cr.close() if verbose: