[IMP] improved code to get translation from database.

bzr revid: tpa@tinyerp.com-20120712085838-pqzj86fptp96eag6
This commit is contained in:
Turkesh Patel (Open ERP) 2012-07-12 14:28:38 +05:30
parent 4ea3ad65b2
commit d87adc497e
2 changed files with 13 additions and 10 deletions

View File

@ -783,7 +783,7 @@ class translation(netsvc.ExportService):
netsvc.ExportService.__init__(self, name)
def exp_load(self, db, modules, langs, flag=None, context=None):
translated_data = []
translated_data = {'messages':[]}
cr = pooler.get_db(db).cursor()
for module_name in modules:
modpath = openerp.modules.get_module_path(module_name)
@ -799,7 +799,9 @@ class translation(netsvc.ExportService):
f2 = openerp.modules.get_module_resource(module_name, 'i18n', iso_lang2 + '.po')
if f2:
_logger.info('module %s: loading base translation file %s for language %s', module_name, iso_lang2, lang)
translated_data.append(tools.trans_load(cr, f2, lang, verbose=False, flag=flag, module_name=module_name, context=context))
trans = tools.trans_load(cr, f2, lang, verbose=False, flag=flag, module_name=module_name, context=context)
if trans:
translated_data['messages'].extend(trans)
context2['overwrite'] = True
# Implementation notice: we must first search for the full name of
# the language derivative, like "en_UK", and then the generic,
@ -809,7 +811,9 @@ class translation(netsvc.ExportService):
f = openerp.modules.get_module_resource(module_name, 'i18n', iso_lang + '.po')
if f:
_logger.info('module %s: loading translation file (%s) for language %s', module_name, iso_lang, lang)
translated_data.append(tools.trans_load(cr, f, lang, verbose=False, flag=flag, module_name=module_name, context=context2))
trans = tools.trans_load(cr, f, lang, verbose=False, flag=flag, module_name=module_name, context=context2)
if trans:
translated_data['messages'].extend(trans)
elif iso_lang != 'en':
_logger.warning('module %s: no translation for language %s', module_name, iso_lang)
cr.commit()

View File

@ -849,12 +849,11 @@ def trans_load(cr, filename, lang, verbose=True, flag=None, module_name=None, co
pool = pooler.get_pool(cr.dbname)
traslation_obj = pool.get('ir.translation')
_logger.info("loading %s", filename)
if flag == 'web':
transl = {"messages":[]}
po = babel.messages.pofile.read_po(fileobj)
for x in po:
if x.id and x.string and "openerp-web" in x.auto_comments:
transl["messages"].append({'id': x.id, 'string': x.string})
if flag == 'web' and module_name == 'web':
transl = []
trans_ids = traslation_obj.search(cr, 1, [('module','=', module_name),('lang','=',lang)])
for trans in traslation_obj.browse(cr, 1, trans_ids, context=context):
transl.append({'id': trans.src, 'string': trans.value})
return transl
else:
fileformat = os.path.splitext(filename)[-1][1:].lower()
@ -913,7 +912,7 @@ def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True,
# dictionary which holds values for this line of the csv file
# {'lang': ..., 'type': ..., 'name': ..., 'res_id': ...,
# 'src': ..., 'value': ...}
# 'src': ..., 'value': ..., 'module':...}
dic = {'lang': lang}
dic_module = False
for i in range(len(f)):