- # -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
#
##############################################################################
-from osv import osv, fields
-from tools.translate import _
+from osv import osv
import wrap_object
import logging
_logger = logging.getLogger(__name__)
for key in translation_list[total_term:limit]:
trans_list.append(key)
total_term = limit
- jobs = meta.pack_jobs_request(cr, uid, trans_list, context={'language_code': context['lang']})
- result = gengo.postTranslationJobs(jobs=jobs)
- self.write(cr, uid, ids, {'state': 'done'})
+ request = meta.pack_jobs_request(cr, uid, trans_list, context={'language_code': context['lang']})
+ result = gengo.postTranslationJobs(jobs=request)
if user.company_id.gengo_tier == 'machine':
- if result.get('opstat') == 'ok':
- for job in result.get('response').get('jobs'):
- for translation_id, val in job.items():
- translation_pool.write(cr, uid, int(translation_id), {'value':
- val['body_tgt'], 'state': 'translated', 'gengo_control': True})
- else:
- for job in result.get('response').get('jobs'):
- for translation_id, val in job.items():
- translation_pool.write(cr, uid, int(translation_id), {'job_id': val['job_id']})
- return
+ response = meta.unpack_jobs_response(result)
+ for job in response.response[1]:
+ for jobs in job:
+ translation_term_id = translation_pool.search(cr, uid, [('src', '=', job[jobs]['body_src'])])
+ translation_pool.write(cr, uid, translation_term_id, {'value': job[jobs]['body_tgt'], 'state': 'translated', 'gengo_control': True})
+ return
def act_update(self, cr, uid, ids, context=None):
+ if context == None:
+ context={}
try:
language_pool = self.pool.get('res.lang')
this = self.browse(cr, uid, ids)[0]
translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', this.lang)])
context.update({'lang': this.lang, 'translation_term_id': translation_term_id})
self.send_translation_terms(cr, uid, ids, context)
- return
+ msg = "Your Request has been Successfully Send to Gengo"
else:
- self.write(cr, uid, ids, {'state': 'inprogress'})
+ msg = "This language is select as Active All Translation Request will be sent by System Automatically"
+
except Exception, e:
- raise osv.except_osv(_('Warning !'), _('%s') % e)
+ msg = '%s' % e
+ context.update({'message': msg})
+ obj_model = self.pool.get('ir.model.data')
+ model_data_ids = obj_model.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'update_translation_wizard_view_confirm')])
+ resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
+ return {
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'gengo.update.message',
+ 'views': [(resource_id, 'form')],
+ 'type': 'ir.actions.act_window',
+ 'target': 'new',
+ 'context': context,
+ }
def scheduler_get_gengo_response(self, cr, uid, ids=0, context=None):
"""Scheduler will be call to get response from gengo and all term will get
by scheduler which terms are in reviewable state"""
-
meta = self.pool.get('jobs.meta')
translation_pool = self.pool.get('ir.translation')
gengo = meta.gengo_authentication(cr, uid, ids, context)
if res:
response = meta.unpack_jobs_response(res)
for job in response.response:
- translation_id = translation_pool.search(cr, uid, [('job_id', '=', job.job_id)], context)
- response = gengo.getTranslationJob(id=job.job_id)
- translation_pool.write(cr, uid, translation_id, {'value': response['response']['job']['body_tgt'], 'state': 'translated', 'gengo_control': True})
+ job_response=gengo.getTranslationJob(id=job['job_id'])
+ jobs_response = meta.unpack_jobs_response(job_response)
+ translation_id = translation_pool.search(cr, uid, [('src', '=', jobs_response.response[0]['body_src'])], context)
+ translation_pool.write(cr, uid, translation_id, {'value': jobs_response.response[0]['body_tgt'], 'state': 'translated', 'gengo_control': True})
def scheduler_get_gengo_sync_request(self, cr, uid, ids=0, context=None):
"""This scheduler will send a job request to the gengo , which terms are
lang_ids = language_pool.read(cr, uid, lang_search_id)
for lang_id in lang_ids:
- translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', lang_id['code']), ('job_id', '=', False)])
+ translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', lang_id['code'])])
context.update({'lang': lang_id['code'], 'translation_term_id': translation_term_id})
if translation_term_id:
self.send_translation_terms(cr, uid, ids, context)
_name = 'base.update.translations'
_inherit = "base.update.translations"
- _columns = {
- 'state': fields.selection([('init', 'init'), ('inprogress', 'inprogress'), ('done', 'done')], 'state'),
- }
-
- _defaults = {
- 'state': 'init',
- }
gengo_update_translation()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: