diff --git a/addons/base_gengo/gengo_sync_schedular_data.xml b/addons/base_gengo/gengo_sync_schedular_data.xml index baf2a639cff..e55066e0e74 100644 --- a/addons/base_gengo/gengo_sync_schedular_data.xml +++ b/addons/base_gengo/gengo_sync_schedular_data.xml @@ -4,7 +4,7 @@ Gengo Sync Translation (Response) - + 20 minutes -1 @@ -16,7 +16,7 @@ Gengo Sync Translation (Request) - + 20 minutes -1 diff --git a/addons/base_gengo/wizard/base_gengo_translations.py b/addons/base_gengo/wizard/base_gengo_translations.py index 2bbe84583d5..79e3897e264 100644 --- a/addons/base_gengo/wizard/base_gengo_translations.py +++ b/addons/base_gengo/wizard/base_gengo_translations.py @@ -111,31 +111,31 @@ class base_gengo_translations(osv.osv_memory): if not flag: _logger.warning("%s", gengo) else: - translation_id = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine','standard','pro','ultra'))], limit=limit, context=context) - for term in translation_pool.browse(cr, uid, translation_id, context=context): - up_term = up_comment = 0 - if term.job_id: - vals={} - job_response = gengo.getTranslationJob(id=term.job_id) - if job_response['opstat'] != 'ok': - _logger.warning("Invalid Response! Skipping translation Terms with `id` %s." % (term.job_id)) - continue - if job_response['response']['job']['status'] == 'approved': - vals.update({'state': 'translated', - 'value': job_response['response']['job']['body_tgt']}) - up_term += 1 - job_comment = gengo.getTranslationJobComments(id=term.job_id) - if job_comment['opstat']=='ok': - gengo_comments="" - for comment in job_comment['response']['thread']: - gengo_comments += _('%s\n\n--\n Commented on %s by %s.') % (comment['body'], time.ctime(comment['ctime']), comment['author']) - vals.update({'gengo_comment': gengo_comments}) - up_comment += 1 - if vals: - translation_pool.write(cr, uid, term.id, vals) - _logger.info("Successfully Updated `%d` terms and %d Comments." % (up_term, up_comment )) - else: - _logger.warning("%s", 'Cannot retrieve the Gengo job ID for translation %s: %s' % (term.id, term.src)) + translation_id = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine','standard','pro','ultra')), ('job_id', "!=",False)], limit=limit, context=context) + translation_terms = translation_pool.browse(cr, uid, translation_id, context=context) + gengo_job_id = [term.job_id for term in translation_terms] + if gengo_job_id: + gengo_ids = ','.join(gengo_job_id) + job_response = gengo.getTranslationJobBatch(id=gengo_ids) + if job_response['opstat'] == 'ok': + job_response_dict = dict([(job['job_id'],job) for job in job_response['response']['jobs']]) + for term in translation_terms: + up_term = up_comment = 0 + vals={} + if job_response_dict[term.job_id]['status'] == 'approved': + vals.update({'state': 'translated', + 'value': job_response_dict[term.job_id]['body_tgt']}) + up_term += 1 + job_comment = gengo.getTranslationJobComments(id=term.job_id) + if job_comment['opstat']=='ok': + gengo_comments="" + for comment in job_comment['response']['thread']: + gengo_comments += _('%s\n-- Commented on %s by %s.\n\n') % (comment['body'], time.ctime(comment['ctime']), comment['author']) + vals.update({'gengo_comment': gengo_comments}) + up_comment += 1 + if vals: + translation_pool.write(cr, uid, term.id, vals) + _logger.info("Successfully Updated `%d` terms and %d Comments." % (up_term, up_comment )) return True def _update_terms(self, cr, uid, response, context=None): @@ -218,7 +218,7 @@ class base_gengo_translations(osv.osv_memory): lang_ids = [context.get('gengo_language')] langs = [lang.code for lang in language_pool.browse(cr, uid, lang_ids, context=context)] #search for the n first terms to translate - term_ids = translation_pool.search(cr, uid, [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine','standard','pro','ultra')), ('lang', 'in', langs)], limit=limit, context=context) + term_ids = translation_pool.search(cr, uid, [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine','standard','pro','ultra')), ('lang', 'in', langs),('job_id',"=",False)], limit=limit, context=context) if term_ids: self._send_translation_terms(cr, uid, term_ids, context=context) _logger.info("%s Translation terms have been posted to Gengo successfully", len(term_ids)) diff --git a/addons/website_gengo/controllers/main.py b/addons/website_gengo/controllers/main.py index 8045916d0eb..6bc2850253d 100644 --- a/addons/website_gengo/controllers/main.py +++ b/addons/website_gengo/controllers/main.py @@ -12,3 +12,11 @@ class website_gengo(http.Controller): for trans in ir_translation_obj.browse(request.cr, request.uid, gengo_translation_ids): result['done'] += len(trans.source.split()) return result + @http.route('/website/check_gengo_set', type='json', auth='user', website=True) + def check_gengo_set(self): + ir_translation_obj = request.registry['res.users'] + user = request.registry['res.users'].browse(request.cr, request.uid, request.uid) + flag = 1 + if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key: + flag = 0 + return flag diff --git a/addons/website_gengo/static/src/js/website_gengo.js b/addons/website_gengo/static/src/js/website_gengo.js index 65e6f83bf6f..92ae13d002f 100644 --- a/addons/website_gengo/static/src/js/website_gengo.js +++ b/addons/website_gengo/static/src/js/website_gengo.js @@ -29,39 +29,51 @@ translation_gengo_post: function () { var self = this; var translatable_list = $.find('.oe_translatable_todo'); - var dialog = new website.GengoTranslatorPostDialog(); - dialog.appendTo($(document.body)); - dialog.on('service_level', this, function () { - var gengo_service_level = dialog.$el.find(".form-control").val(); - dialog.$el.modal('hide'); - self.$el.find('.gengo_post').addClass("hidden"); - self.$el.find('.gengo_wait').removeClass("hidden"); - var trans ={} - $('.oe_translatable_todo').each(function () { - var $node = $(this); - var data = $node.data(); - if (!trans[data.oeTranslationViewId]) { - trans[data.oeTranslationViewId] = []; - } - trans[data.oeTranslationViewId].push({ - initial_content: self.getInitialContent(this), - new_content:self.getInitialContent(this), - translation_id: data.oeTranslationId || null, - gengo_translation: gengo_service_level, - gengo_comment:"Original page:" + document.URL + this.new_words = 0; + $('.oe_translatable_todo').each(function () { + self.new_words += $(this).text().trim().replace(/ +/g," ").split(" ").length; + }); + openerp.jsonRpc('/website/check_gengo_set', 'call', { + }).then(function (res) { + if (res == 1){ + var dialog = new website.GengoTranslatorPostDialog(self.new_words); + dialog.appendTo($(document.body)); + dialog.on('service_level', this, function () { + var gengo_service_level = dialog.$el.find(".form-control").val(); + dialog.$el.modal('hide'); + self.$el.find('.gengo_post').addClass("hidden"); + self.$el.find('.gengo_wait').removeClass("hidden"); + var trans ={} + $('.oe_translatable_todo').each(function () { + var $node = $(this); + var data = $node.data(); + if (!trans[data.oeTranslationViewId]) { + trans[data.oeTranslationViewId] = []; + } + trans[data.oeTranslationViewId].push({ + initial_content: self.getInitialContent(this), + new_content:self.getInitialContent(this), + translation_id: data.oeTranslationId || null, + gengo_translation: gengo_service_level, + gengo_comment:"Original page:" + document.URL + }); + }); + openerp.jsonRpc('/website/set_translations', 'call', { + 'data': trans, + 'lang': website.get_context()['lang'], + }).then(function () { + $('.oe_translatable_todo').addClass('oe_translatable_inprogress').removeClass('oe_translatable_todo'); + self.$el.find('.gengo_wait').addClass("hidden"); + self.$el.find('.gengo_inprogress,.gengo_discard').removeClass("hidden"); + self.save(); + }).fail(function () { + alert("Could not Post translation"); + }); }); - }); - openerp.jsonRpc('/website/set_translations', 'call', { - 'data': trans, - 'lang': website.get_context()['lang'], - }).then(function () { - $('.oe_translatable_todo').addClass('oe_translatable_inprogress').removeClass('oe_translatable_todo'); - self.$el.find('.gengo_wait').addClass("hidden"); - self.$el.find('.gengo_inprogress,.gengo_discard').removeClass("hidden"); - self.save(); - }).fail(function () { - alert("Could not Post translation"); - }); + }else{ + var dialog = new website.GengoApiConfigDialog(); + dialog.appendTo($(document.body)); + } }); }, @@ -91,6 +103,10 @@ }, }), template: 'website.GengoTranslatorPostDialog', + init:function(new_words){ + this.new_words = new_words; + return this._super.apply(this, arguments); + }, start: function () { this.$el.modal(); }, @@ -119,5 +135,14 @@ this.$el.modal(this.res); }, }); + website.GengoApiConfigDialog = openerp.Widget.extend({ + events: _.extend({}, website.EditorBar.prototype.events, { + 'hidden.bs.modal': 'destroy', + }), + template: 'website.GengoApiConfigDialog', + start: function (res) { + this.$el.modal(this.res); + }, + }); })(); diff --git a/addons/website_gengo/static/src/xml/website.gengo.xml b/addons/website_gengo/static/src/xml/website.gengo.xml index 663eb982cbb..ea5be56bab7 100644 --- a/addons/website_gengo/static/src/xml/website.gengo.xml +++ b/addons/website_gengo/static/src/xml/website.gengo.xml @@ -63,10 +63,10 @@ @@ -105,5 +105,26 @@ + + +