[MERGE] merged the branch with enhancements of ir.translation. Those changes are needed for base_gengo module

bzr revid: qdp-launchpad@openerp.com-20120831125336-0f515b4b4aaucw16
This commit is contained in:
Quentin (OpenERP) 2012-08-31 14:53:36 +02:00
commit 2e919967c3
3 changed files with 23 additions and 8 deletions

View File

@ -1185,6 +1185,9 @@
<field name="model">ir.translation</field>
<field name="arch" type="xml">
<form string="Translations" version="7.0">
<header>
<field name="state" widget="statusbar" nolabel="1"/>
</header>
<sheet>
<group>
<group>

View File

@ -77,14 +77,14 @@ class ir_translation_import_cursor(object):
def push(self, ddict):
"""Feed a translation, as a dictionary, into the cursor
"""
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)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""",
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']))
ddict['value'],state))
def finish(self):
""" Transfer the data from the temp table to ir.translation
@ -125,15 +125,16 @@ class ir_translation_import_cursor(object):
# Step 2: update existing (matching) translations
if self._overwrite:
cr.execute("""UPDATE ONLY %s AS irt
SET value = ti.value
SET value = ti.value,
state = 'translated'
FROM %s AS ti
WHERE %s AND ti.value IS NOT NULL AND ti.value != ''
""" % (self._parent_table, self._table_name, find_expr))
# 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,state)
SELECT name, lang, res_id, src, type, value,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))
@ -167,6 +168,11 @@ 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'),
'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)',
@ -301,6 +307,10 @@ class ir_translation(osv.osv):
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
if vals.get('src') or ('value' in vals and not(vals.get('value'))):
result = vals.update({'state':'to_translate'})
if vals.get('value'):
result = vals.update({'state':'translated'})
result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)
for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
self._get_source.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['src'])

View File

@ -10,7 +10,9 @@
<field name="lang"/>
</group>
<footer>
<button name="act_cancel" special="cancel" string="Cancel" type="object"/>
<button name="act_update" string="Update" type="object" class="oe_highlight"/>
or
<button name="act_cancel" special="cancel" string="Cancel" type="object" class="oe_link"/>
</footer>
</form>
</field>