[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
This commit is contained in:
parent
ff55f829ce
commit
edcbf91f03
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue