Show bing suggest errors.

This commit is contained in:
Kit Sunde 2012-02-24 18:37:21 +08:00
parent 5593635e1e
commit 9fbf953216

View file

@ -4,53 +4,43 @@ google.setOnLoadCallback(function() {
}, function() {
$('.hide', $(this).parent()).hide();
});
{% if ENABLE_TRANSLATION_SUGGESTIONS and BING_APP_ID %}
$('a.suggest').click(function() {
var a = $(this),
str = a.html(),
orig = $('.original .message', a.parents('tr')).html(),
trans=$('textarea',a.parent()),
sourceLang = '{{MESSAGES_SOURCE_LANGUAGE_CODE}}',
destLang = '{{rosetta_i18n_lang_code|slice:":2"}}',
app_id = '{{BING_APP_ID}}';
orig = unescape(orig).replace(/<br\s?\/?>/g,'\n').replace(/<code>/g,'').replace(/<\/code>/g,'').replace(/&gt;/g,'>').replace(/&lt;/g,'<');
$('a.suggest').click(function(e){
e.preventDefault();
var a = $(this);
var str = a.html();
var orig = $('.original .message', a.parents('tr')).html();
var trans=$('textarea',a.parent());
var sourceLang = '{{ MESSAGES_SOURCE_LANGUAGE_CODE }}';
var destLang = '{{ rosetta_i18n_lang_code|slice:":2" }}';
var app_id = '{{ BING_APP_ID }}';
var apiUrl = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate";
orig = unescape(orig).replace(/<br\s?\/?>/g,'\n').replace(/<code>/,'').replace(/<\/code>/g,'').replace(/&gt;/g,'>').replace(/&lt;/g,'<');
a.attr('class','suggesting').html('...');
window.onTranslationComplete = function(resp) {
trans.val(unescape(resp).replace(/&#39;/g,'\'').replace(/&quot;/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s '));
a.hide();
};
var s = document.createElement("script");
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=onTranslationComplete&appId="+app_id +"&from=" + sourceLang + "&to=" + destLang + "&text=" + orig;
document.getElementsByTagName("head")[0].appendChild(s);
/*
google.language.translate(orig, , function(result) {
if (!result.error) {
trans.val(unescape(result.translation).replace(/&#39;/g,'\'').replace(/&quot;/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s '));
a.hide();
} else {
a.hide().before($('<span class="alert">'+result.error.message+'</span>'));
}
});
*/
return false;
window.onTranslationError = function(response){
a.text(response);
};
var apiData = {
onerror: 'onTranslationError',
appid: app_id,
from: sourceLang,
to: destLang,
text: orig
};
$.ajax({
url: apiUrl,
data: apiData,
dataType: 'jsonp',
jsonpCallback: 'onTranslationComplete'});
});
$('#translate-all').submit(function() {
$('a.suggest').click();
return false;
});
$('.checkall').click(function(){
$('td.c input').attr('checked', '');
$('td.c input').attr('value', '0');
});
{% endif %}
$('td.plural').each(function(i) {
var td = $(this), trY = parseInt(td.closest('tr').offset().top);
$('textarea', $(this).closest('tr')).each(function(j) {