[IMP] translation: Added two columns to ir_translation to fix the res_ids after loading is done.

Currently res_ids are resolved and written to ir_translation on the fly, as
the .po are loaded, line by line. Doing this in a second step should resolve
a translation bug and make things faster too.

bzr revid: vmt@openerp.com-20110106105021-xj9vah5oz0ceto7i
This commit is contained in:
Vo Minh Thu 2011-01-06 11:50:21 +01:00
parent fb52e88957
commit 4629c7af78
2 changed files with 26 additions and 11 deletions

View File

@ -61,6 +61,8 @@ class ir_translation(osv.osv):
'type': fields.selection(TRANSLATION_TYPE, string='Type', size=16, select=True),
'src': fields.text('Source'),
'value': fields.text('Translation Value'),
'module': fields.char('Module', size=64), # TODO foreign key to ir_model_data
'xml_id': fields.char('XML Id', size=128), # idem
}
def _auto_init(self, cr, context={}):
@ -88,7 +90,10 @@ class ir_translation(osv.osv):
cr.execute('CREATE INDEX ir_translation_ltn ON ir_translation (name, lang, type)')
cr.commit()
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_mx',))
if not cr.fetchone():
cr.execute('CREATE INDEX ir_translation_mx ON ir_translation (module, xml_id)')
cr.commit()
@tools.cache(skiparg=3, multi='ids')
def _get_ids(self, cr, uid, name, tt, lang, ids):

View File

@ -846,6 +846,9 @@ def trans_load(cr, filename, lang, verbose=True, context=None):
logger.error("couldn't read translation file %s", filename)
return None
# Populates the ir_translation table. Fixing the res_ids so that they point
# correctly to ir_model_data is done in a separate step, using the
# 'trans_update_res_ids' function below.
def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True, context=None):
logger = logging.getLogger('i18n')
if verbose:
@ -936,17 +939,13 @@ def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True,
try:
dic['res_id'] = dic['res_id'] and int(dic['res_id']) or 0
dic['module'] = False
dic['xml_id'] = False
except:
model_data_ids = model_data_obj.search(cr, uid, [
('model', '=', dic['name'].split(',')[0]),
('module', '=', dic['res_id'].split('.', 1)[0]),
('name', '=', dic['res_id'].split('.', 1)[1]),
])
if model_data_ids:
dic['res_id'] = model_data_obj.browse(cr, uid,
model_data_ids[0]).res_id
else:
dic['res_id'] = False
splitted = dic['res_id'].split('.', 1)
dic['module'] = splitted[0]
dic['xml_id'] = splitted[1]
dic['res_id'] = False
args = [
('lang', '=', lang),
@ -968,6 +967,17 @@ def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True,
filename = '[lang: %s][format: %s]' % (iso_lang or 'new', fileformat)
logger.exception("couldn't read translation file %s", filename)
def trans_update_res_ids(cr):
cr.execute("""\
update ir_translation
set res_id = ir_model_data.res_id
from ir_model_data
where ir_translation.module = ir_model_data.module
and ir_translation.xml_id = ir_model_data.name
and ir_translation.module is not null
and ir_translation.xml_id is not null;
""")
def get_locales(lang=None):
if lang is None:
lang = locale.getdefaultlocale()[0]