imd_name VARCHAR(128)
) INHERITS (%s) ''' % (self._table_name, self._parent_table))
-- def push(self, ddict):
++ def push(self, trans_dict):
"""Feed a translation, as a dictionary, into the cursor
"""
-
- self._cr.execute("INSERT INTO " + self._table_name \
- + """(name, lang, res_id, src, type,
- 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('module'), ddict.get('imd_name'),
- ddict['value']))
- state = "translated" if (ddict['value'] and ddict['value'] != "") else "to_translate"
- self._cr.execute("INSERT INTO " + self._table_name \
- + """(name, lang, res_id, src, type,
- imd_model, imd_module, imd_name, value,state)
- VALUES(%s, %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['value'],state))
++ params = dict(trans_dict,
++ state="translated" if trans_dict['value'] else "to_translate")
++ self._cr.execute("""INSERT INTO %s (name, lang, res_id, src, type, imd_model, module, imd_name, value, state)
++ VALUES (%(name)s, %(lang)s, %(res_id)s, %(src)s, %(type)s, %(imd_model)s, %(module)s, %(imd_name)s, %(value)s, %(state)s)""",
++ params)
def finish(self):
""" Transfer the data from the temp table to ir.translation
# Step 3: insert new translations
- cr.execute("""INSERT INTO %s(name, lang, res_id, src, type, value, module)
- SELECT name, lang, res_id, src, type, value, module
- cr.execute("""INSERT INTO %s(name, lang, res_id, src, type, value,state)
- SELECT name, lang, res_id, src, type, value,state
++ cr.execute("""INSERT INTO %s(name, lang, res_id, src, type, value, module, state)
++ SELECT name, lang, res_id, src, type, value, module, state
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'),
- 'state':fields.selection([('to_translate','To Translate'),('inprogress','Translation in Progress'),('translated','Translated')])
+ 'module': fields.char('Module Name', size=128),
++ 'state': fields.selection([('to_translate','To Translate'),
++ ('inprogress','Translation in Progress'),
++ ('translated','Translated')])
+ }
+
+ _defaults = {
+ 'state':'to_translate',
}
_sql_constraints = [ ('lang_fkey_res_lang', 'FOREIGN KEY(lang) REFERENCES res_lang(code)',
# dictionary which holds values for this line of the csv file
# {'lang': ..., 'type': ..., 'name': ..., 'res_id': ...,
- # 'src': ..., 'value': ...}
- dic = {'lang': lang}
- dic_module = False
- for i in range(len(f)):
- if f[i] in ('module',):
+ # 'src': ..., 'value': ..., 'module':...}
- dic = {'lang': lang}
- dic_module = False
- for i in range(len(f)):
- if f[i] in ('module',):
++ dic = dict.fromkeys(('name', 'res_id', 'src', 'type', 'imd_model', 'imd_name', 'module', 'value'))
++ dic['lang'] = lang
++ for i, field in enumerate(f):
++ if field == 'module':
continue
-- dic[f[i]] = row[i]
++ dic[field] = row[i]
# This would skip terms that fail to specify a res_id
-- if not dic.get('res_id', False):
++ if not dic.get('res_id'):
continue
res_id = dic.pop('res_id')
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]
-- if '.' in res_id:
-- tmodule, tname = res_id.split('.', 1)
-- else:
-- tmodule = dic_module
-- tname = res_id
-- dic['imd_model'] = tmodel
- 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.",
- dic['res_id'], exc_info=True)
- dic['res_id'] = None
- dic['imd_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.",
- dic['res_id'], exc_info=True)
- dic['res_id'] = None
++ tmodel = dic['name'].split(',')[0]
++ if '.' in res_id:
++ tmodule, tname = res_id.split('.', 1)
++ else:
++ tmodule = False
++ tname = res_id
++ dic['imd_model'] = tmodel
++ dic['imd_name'] = tname
++ dic['module'] = tmodule
++ dic['res_id'] = None
irt_cursor.push(dic)