cr.execute('''CREATE TEMP TABLE %s(
imd_model VARCHAR(64),
- imd_module VARCHAR(64),
imd_name VARCHAR(128)
) INHERITS (%s) ''' % (self._table_name, self._parent_table))
self._cr.execute("INSERT INTO " + self._table_name \
+ """(name, lang, res_id, src, type,
- imd_model, imd_module, imd_name, value)
+ imd_model, module, imd_name, value)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""",
(ddict['name'], ddict['lang'], ddict.get('res_id'), ddict['src'], ddict['type'],
- ddict.get('imd_model'), ddict.get('imd_module'), ddict.get('imd_name'),
+ ddict.get('imd_model'), ddict.get('module'), ddict.get('imd_name'),
ddict['value']))
def finish(self):
SET res_id = imd.res_id
FROM ir_model_data AS imd
WHERE ti.res_id IS NULL
- AND ti.imd_module IS NOT NULL AND ti.imd_name IS NOT NULL
+ AND ti.module IS NOT NULL AND ti.imd_name IS NOT NULL
- AND ti.imd_module = imd.module AND ti.imd_name = imd.name
+ AND ti.module = imd.module AND ti.imd_name = imd.name
AND ti.imd_model = imd.model; """ % self._table_name)
if self._debug:
- cr.execute("SELECT imd_module, imd_model, imd_name FROM %s " \
- "WHERE res_id IS NULL AND imd_module IS NOT NULL" % self._table_name)
+ cr.execute("SELECT module, imd_model, imd_name FROM %s " \
+ "WHERE res_id IS NULL AND module IS NOT NULL" % self._table_name)
for row in cr.fetchall():
_logger.debug("ir.translation.cursor: missing res_id for %s. %s/%s ", *row)
- cr.execute("DELETE FROM %s WHERE res_id IS NULL AND imd_module IS NOT NULL" % \
+ cr.execute("DELETE FROM %s WHERE res_id IS NULL AND module IS NOT NULL" % \
self._table_name)
# Records w/o res_id must _not_ be inserted into our db, because they are
# Step 3: insert new translations
- cr.execute("""INSERT INTO %s(name, lang, res_id, src, type, value)
- SELECT name, lang, res_id, src, type, value
+ cr.execute("""INSERT INTO %s(name, lang, res_id, src, type, value, module)
+ SELECT name, lang, res_id, src, type, value, module
FROM %s AS ti
WHERE NOT EXISTS(SELECT 1 FROM ONLY %s AS irt WHERE %s);
""" % (self._parent_table, self._table_name, self._parent_table, find_expr))
'type': fields.selection(TRANSLATION_TYPE, string='Type', size=16, select=True),
'src': fields.text('Source'),
'value': fields.text('Translation Value'),
+ 'module': fields.char('Module Name', size=128),
}
_sql_constraints = [ ('lang_fkey_res_lang', 'FOREIGN KEY(lang) REFERENCES res_lang(code)',
f2 = modules.get_module_resource(mod.name, 'i18n', iso_lang2 + '.po')
if f2:
_logger.info('module %s: loading base translation file %s for language %s', mod.name, iso_lang2, lang)
- tools.trans_load(cr, f2, lang, verbose=False, context=context)
+ tools.trans_load(cr, f2, lang, verbose=False, module_name=mod.name, context=context)
context2['overwrite'] = True
# Implementation notice: we must first search for the full name of
# the language derivative, like "en_UK", and then the generic,
f = modules.get_module_resource(mod.name, 'i18n', iso_lang + '.po')
if f:
_logger.info('module %s: loading translation file (%s) for language %s', mod.name, iso_lang, lang)
- tools.trans_load(cr, f, lang, verbose=False, context=context2)
+ tools.trans_load(cr, f, lang, verbose=False, module_name=mod.name, context=context2)
elif iso_lang != 'en':
_logger.warning('module %s: no translation for language %s', mod.name, iso_lang)
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, context=context))
+ translated_data.append(tools.trans_load(cr, f2, lang, verbose=False, flag=flag, module_name=module_name, context=context))
context2['overwrite'] = True
# Implementation notice: we must first search for the full name of
# the language derivative, like "en_UK", and then the generic,
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, context=context2))
+ translated_data.append(tools.trans_load(cr, f, lang, verbose=False, flag=flag, module_name=module_name, context=context2))
elif iso_lang != 'en':
_logger.warning('module %s: no translation for language %s', module_name, iso_lang)
cr.commit()
return out
-def trans_load(cr, filename, lang, verbose=True, flag=None, context=None):
+def trans_load(cr, filename, lang, verbose=True, flag=None, module_name=None, context=None):
try:
fileobj = misc.file_open(filename)
pool = pooler.get_pool(cr.dbname)
return transl
else:
fileformat = os.path.splitext(filename)[-1][1:].lower()
- r = trans_load_data(cr, fileobj, fileformat, lang, verbose=verbose, context=context)
+ r = trans_load_data(cr, fileobj, fileformat, lang, verbose=verbose, module_name=module_name, context=context)
fileobj.close()
return r
except IOError:
_logger.error("couldn't read translation file %s", filename)
return None
-def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True, context=None):
+def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True, module_name=None, context=None):
"""Populates the ir_translation table."""
if verbose:
_logger.info('loading translation file for language %s', lang)
break
elif fileformat == 'po':
reader = TinyPoFile(fileobj)
- f = ['type', 'name', 'res_id', 'src', 'value']
+ f = ['type', 'name', 'res_id', 'src', 'value', 'module']
else:
_logger.error('Bad file format: %s', fileformat)
raise Exception(_('Bad file format'))
if res_id and isinstance(res_id, (int, long)) \
or (isinstance(res_id, basestring) and res_id.isdigit()):
dic['res_id'] = int(res_id)
+ dic['module'] = module_name
else:
try:
tmodel = dic['name'].split(',')[0]
tmodule = dic_module
tname = res_id
dic['imd_model'] = tmodel
- dic['imd_module'] = tmodule
+ dic['module'] = tmodule
dic['imd_name'] = tname
-
dic['res_id'] = None
except Exception:
_logger.warning("Could not decode resource for %s, please fix the po file.",