diff options
| author | Vo Minh Thu (OpenERP) <vmt@openerp.com> | 2010-12-21 11:58:43 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2010-12-21 11:58:43 +0100 |
| commit | 35b9fd82ffd4abc420791b4fc8df26d60282a4a9 (patch) | |
| tree | d5fb5dbb8380c70ae4df43f9832c01013846066b | |
| parent | 78a2174db179b87758c7482fff7234a7e52f7d97 (diff) | |
[FIX] re-commit previous merge broken by bzr-rebase:
translate,orm: simplify loading of field value translations and avoid ignoring them when string has changed (many issues with menus not loaded yet)
bzr revid: odo@openerp.com-20101221105843-myzlkd74tci3puer
| -rw-r--r-- | bin/osv/orm.py | 2 | ||||
| -rw-r--r-- | bin/tools/translate.py | 60 |
2 files changed, 17 insertions, 45 deletions
diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c5eea32671f..68e3c511f53 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 76d41d25054..582cd9d8303 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,48 +924,20 @@ 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(',') - - # 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 - 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) + args = [ + ('lang', '=', lang), + ('type', '=', dic['type']), + ('name', '=', dic['name']), + ('src', '=', dic['src']), + ] + if dic['type'] == 'model': + args.append(('res_id', '=', dic['res_id'])) + ids = trans_obj.search(cr, uid, args) + if ids: + if context.get('overwrite'): + 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: |
