[IMP] opened dialog if api key not set, final total in dropdown, improved requests in base_gengo

bzr revid: pga@tinyerp.com-20140325141308-5h2rtlbm2ctytbt1
This commit is contained in:
Parth Gajjar (Open ERP) 2014-03-25 19:43:08 +05:30
parent 2971b56c14
commit 744b4bb2b6
5 changed files with 118 additions and 64 deletions

View File

@ -4,7 +4,7 @@
<!--Scheduler sync Receive Request-->
<record id="gengo_sync_receive_request_scheduler" model="ir.cron">
<field name="name" >Gengo Sync Translation (Response)</field>
<field eval="False" name="active"/>
<field eval="True" name="active"/>
<field name="interval_number">20</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
@ -16,7 +16,7 @@
<!--Scheduler Sync Send Request-->
<record id="gengo_sync_send_request_scheduler" model="ir.cron">
<field name="name" >Gengo Sync Translation (Request)</field>
<field eval="False" name="active"/>
<field eval="True" name="active"/>
<field name="interval_number">20</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>

View File

@ -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))

View File

@ -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

View File

@ -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);
},
});
})();

View File

@ -63,10 +63,10 @@
<div class="modal-body">
<section>
<select class="form-control" required="required" autofocus="autofocus">
<option value="machine">Machine (Free)</option>
<option value="standard">Standard - $0.05 per word</option>
<option value="pro">Pro - $0.10 per word</option>
<option value="ultra">Ultra - $0.15 per word</option>
<option value="machine">By Machine (Free)</option>
<option value="standard">Standard - $ <t t-esc="(widget.new_words * 0.05).toFixed(2)"></t> </option>
<option value="pro">Pro - $ <t t-esc="(widget.new_words * 0.10).toFixed(2)"></t></option>
<option value="ultra">Ultra - $ <t t-esc="(widget.new_words * 0.15).toFixed(2)"></t></option>
</select>
</section>
</div>
@ -105,5 +105,26 @@
</div>
</div>
</t>
<t t-name="website.GengoApiConfigDialog">
<div class="modal fade oe_website_translator" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button title="Close" type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Gengo API key not set</h2>
</div>
<div class="modal-body">
<b> <h3>Steps for configure a Gengo </h3>
<div class="mb16"> 1. Go To your <b><a target="new" href="https://gengo.com/account/api_settings/">gengo account</a></b> and generate API Keys.</div>
<div class="mb16"> 2. Then copy generate keys in <a href="/web#return_label=Website&amp;model=res.company&amp;id=1">Your company data</a></div>
</b>
</div>
<div class="modal-footer">
<a data-action="discard" data-dismiss="modal" href="#">Close</a>
</div>
</div>
</div>
</div>
</t>
</templates>