Changeset 351
- Timestamp:
- 01/12/2010 09:01:54 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/js/transposh.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/js/transposh.js
r349 r351 18 18 19 19 // fetch translation from google translate... 20 function getgt() 21 { 22 if (typeof google == 'undefined') { 23 langLoaded = function() { 24 getgt(); 25 }; 26 jQuery.xLazyLoader({ 27 js: 'http://www.google.com/jsapi?callback=loadLang' 28 }); 29 } else { 30 jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled"); 31 google.language.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", _tr_p.lang, function(result) { 32 if (!result.error) { 33 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+result.translation+"</div>").text()) 34 .keyup(); 35 } 36 }); 37 } 38 } 39 40 // fetch translation from bing translate... 41 function getbt() 42 { 43 if (typeof Microsoft == 'undefined') { 44 jQuery.xLazyLoader({ 45 js: 'http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId='+_tr_p.msnkey, 46 success: function() { 47 getbt() 48 } 49 }); 50 51 } else { 52 jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled"); 53 var binglang = _tr_p.lang; 54 if (binglang == 'zh') { 55 binglang = 'zh-chs' 56 } 57 if (binglang == 'zh-tw') { 58 binglang = 'zh-cht' 59 } 60 try { 61 Microsoft.Translator.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", binglang, function(translation) { 62 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+translation+"</div>").text()) 63 .keyup(); 20 (function () { // closure 21 function getgt() 22 { 23 if (typeof google == 'undefined') { 24 langLoaded = function() { 25 getgt(); 26 }; 27 jQuery.xLazyLoader({ 28 js: 'http://www.google.com/jsapi?callback=loadLang' 64 29 }); 65 } 66 catch (err) { 67 alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")"); 68 } 69 } 70 } 71 72 //Ajax translation 73 var done_p = 0; 74 var togo = 0; 75 //Timer for translation aggregation 76 var timer; 77 var tokens = new Array(); 78 var translations = new Array(); 79 80 function ajax_translate(translation,source,segment_id) { 81 // we aggregate translations together, 200ms from the last translation we will send the timer 82 // so here we remove it so nothing unexpected happens 83 clearTimeout(timer); 84 // push translations 85 tokens.push(jQuery("#"+_tr_p.prefix + segment_id).attr('token')); 86 translations.push(translation); 87 // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 88 fix_page(translation,source,segment_id); 89 timer = setTimeout(function() { 90 var data = { 91 lang: _tr_p.lang, 92 source: source, 93 translation_posted: "1", 94 items: tokens.length 95 }; 96 for (var i = 0; i < tokens.length; i++) { 97 data["tk"+i] = tokens[i]; 98 data["tr"+i] = translations[i]; 99 // We are pre-accounting the progress bar here - which is not very nice 100 if (source > 0) { 101 done_p += jQuery("*[token='"+tokens[i]+"']").size(); 102 } 103 } 104 jQuery.ajax({ 105 type: "POST", 106 url: _tr_p.post_url, 107 data: data, 108 success: function() { 109 // Success now only updates the save progress bar (green) 110 if (_tr_p.progress) { 111 if (togo > 4 && source > 0) { 112 jQuery("#progress_bar2").progressbar('value' , done_p/togo*100); 30 } else { 31 jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled"); 32 google.language.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", _tr_p.lang, function(result) { 33 if (!result.error) { 34 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+result.translation+"</div>").text()) 35 .keyup(); 36 } 37 }); 38 } 39 } 40 41 // fetch translation from bing translate... 42 function getbt() 43 { 44 if (typeof Microsoft == 'undefined') { 45 jQuery.xLazyLoader({ 46 js: 'http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId='+_tr_p.msnkey, 47 success: function() { 48 getbt() 49 } 50 }); 51 52 } else { 53 jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled"); 54 var binglang = _tr_p.lang; 55 if (binglang == 'zh') { 56 binglang = 'zh-chs' 57 } 58 if (binglang == 'zh-tw') { 59 binglang = 'zh-cht' 60 } 61 try { 62 Microsoft.Translator.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", binglang, function(translation) { 63 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+translation+"</div>").text()) 64 .keyup(); 65 }); 66 } 67 catch (err) { 68 alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")"); 69 } 70 } 71 } 72 73 //Ajax translation 74 var done_p = 0; 75 var togo = 0; 76 //Timer for translation aggregation 77 var timer; 78 var tokens = new Array(); 79 var translations = new Array(); 80 81 function ajax_translate(translation,source,segment_id) { 82 // we aggregate translations together, 200ms from the last translation we will send the timer 83 // so here we remove it so nothing unexpected happens 84 clearTimeout(timer); 85 // push translations 86 tokens.push(jQuery("#"+_tr_p.prefix + segment_id).attr('token')); 87 translations.push(translation); 88 // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 89 fix_page(translation,source,segment_id); 90 timer = setTimeout(function() { 91 var data = { 92 lang: _tr_p.lang, 93 source: source, 94 translation_posted: "1", 95 items: tokens.length 96 }; 97 for (var i = 0; i < tokens.length; i++) { 98 data["tk"+i] = tokens[i]; 99 data["tr"+i] = translations[i]; 100 // We are pre-accounting the progress bar here - which is not very nice 101 if (source > 0) { 102 done_p += jQuery("*[token='"+tokens[i]+"']").size(); 103 } 104 } 105 jQuery.ajax({ 106 type: "POST", 107 url: _tr_p.post_url, 108 data: data, 109 success: function() { 110 // Success now only updates the save progress bar (green) 111 if (_tr_p.progress) { 112 if (togo > 4 && source > 0) { 113 jQuery("#progress_bar2").progressbar('value' , done_p/togo*100); 114 } 115 113 116 } 114 115 } 116 }, 117 }, 117 118 118 error: function(req) { 119 if (source == 0) { 120 alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 121 } 122 } 123 }); 124 translations = []; 125 tokens = []; 126 }, 200); // wait 200 ms... 127 } 128 129 function fix_page(translation,source,segment_id) { 130 var token = jQuery("#"+_tr_p.prefix + segment_id).attr('token'); 131 var new_text = translation; 132 //reset to the original content - the unescaped version if translation is empty 133 if(jQuery.trim(translation).length === 0) { 134 new_text = jQuery("#"+_tr_p.prefix + segment_id).attr('orig'); 135 } 136 // rewrite text for all matching items at once 137 jQuery("*[token='"+token+"'][hidden!='y']") 138 .html(new_text) 139 .each(function (i) { // handle the image changes 140 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 141 jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 142 var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 143 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 144 if(jQuery.trim(translation).length !== 0) { 145 if (source == 1) { 146 //switch to the auto img 147 img.addClass('tr-icon-yellow'); 148 } else { 149 // switch to the fix img 150 img.addClass('tr-icon-green'); 151 } 152 } 153 }); 154 155 // FIX hidden elements too (need to update father's title) 156 jQuery("*[token='"+token+"'][hidden='y']") 157 .attr('trans',new_text) 158 .each(function (i) { // handle the image changes 159 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 160 jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 161 var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 162 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 163 if(jQuery.trim(translation).length !== 0) { 164 if (source == 1) { 165 //switch to the auto img 166 img.addClass('tr-icon-yellow'); 167 } else { 168 // switch to the fix img 169 img.addClass('tr-icon-green'); 170 } 171 } 172 }); 173 174 } 175 176 //function for auto translation 177 function do_auto_translate() { 178 if (_tr_p.progress) { 179 togo = jQuery("."+_tr_p.prefix+'[source=""]').size(); 180 //alert(togo); 181 // progress bar is for alteast 5 items 182 if (togo > 4) { 183 jQuery("#"+_tr_p.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>') 184 jQuery("#progress_bar").progressbar({ 185 value: 0 119 error: function(req) { 120 if (source == 0) { 121 alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 122 } 123 } 186 124 }); 187 jQuery("#progress_bar2").progressbar({ 188 value: 0 189 }); 190 // color the "save" bar 191 jQuery("#progress_bar2 > div").css({ 192 'background':'#28F828', 193 'border' : "#08A908 1px solid" 194 }); 195 } 196 var done = 0; 197 } 198 // auto_translated_previously... 199 var auto_t_p = new Array(); 200 jQuery("."+_tr_p.prefix+'[source=""]').each(function (i) { 201 var translated_id = jQuery(this).attr('id'); 202 //alert(translated_id); 203 var to_trans = jQuery(this).attr('orig'); 204 if (to_trans == undefined) to_trans = jQuery(this).html(); 205 if (!(auto_t_p[to_trans] == 1)) { 206 auto_t_p[to_trans] = 1; 207 google.language.translate(to_trans, "", _tr_p.lang, function(result) { 208 if (!result.error) { 209 var segment_id = translated_id.substr(translated_id.lastIndexOf('_')+1); 210 // No longer need because now included in the ajax translate 211 //fix_page(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 212 ajax_translate(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 213 if (_tr_p.progress) { 214 done = togo - jQuery("."+_tr_p.prefix+'[source=""]').size(); 215 if (togo > 4) { 216 jQuery("#progress_bar").progressbar('value' , done/togo*100); 125 translations = []; 126 tokens = []; 127 }, 200); // wait 200 ms... 128 } 129 130 function fix_page(translation,source,segment_id) { 131 var token = jQuery("#"+_tr_p.prefix + segment_id).attr('token'); 132 var new_text = translation; 133 //reset to the original content - the unescaped version if translation is empty 134 if(jQuery.trim(translation).length === 0) { 135 new_text = jQuery("#"+_tr_p.prefix + segment_id).attr('orig'); 136 } 137 // rewrite text for all matching items at once 138 jQuery("*[token='"+token+"'][hidden!='y']") 139 .html(new_text) 140 .each(function (i) { // handle the image changes 141 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 142 jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 143 var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 144 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 145 if(jQuery.trim(translation).length !== 0) { 146 if (source == 1) { 147 //switch to the auto img 148 img.addClass('tr-icon-yellow'); 149 } else { 150 // switch to the fix img 151 img.addClass('tr-icon-green'); 152 } 153 } 154 }); 155 156 // FIX hidden elements too (need to update father's title) 157 jQuery("*[token='"+token+"'][hidden='y']") 158 .attr('trans',new_text) 159 .each(function (i) { // handle the image changes 160 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 161 jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 162 var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 163 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 164 if(jQuery.trim(translation).length !== 0) { 165 if (source == 1) { 166 //switch to the auto img 167 img.addClass('tr-icon-yellow'); 168 } else { 169 // switch to the fix img 170 img.addClass('tr-icon-green'); 171 } 172 } 173 }); 174 175 } 176 177 //function for auto translation 178 function do_auto_translate() { 179 if (_tr_p.progress) { 180 togo = jQuery("."+_tr_p.prefix+'[source=""]').size(); 181 //alert(togo); 182 // progress bar is for alteast 5 items 183 if (togo > 4) { 184 jQuery("#"+_tr_p.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>') 185 jQuery("#progress_bar").progressbar({ 186 value: 0 187 }); 188 jQuery("#progress_bar2").progressbar({ 189 value: 0 190 }); 191 // color the "save" bar 192 jQuery("#progress_bar2 > div").css({ 193 'background':'#28F828', 194 'border' : "#08A908 1px solid" 195 }); 196 } 197 var done = 0; 198 } 199 // auto_translated_previously... 200 var auto_t_p = new Array(); 201 jQuery("."+_tr_p.prefix+'[source=""]').each(function (i) { 202 var translated_id = jQuery(this).attr('id'); 203 //alert(translated_id); 204 var to_trans = jQuery(this).attr('orig'); 205 if (to_trans == undefined) to_trans = jQuery(this).html(); 206 if (!(auto_t_p[to_trans] == 1)) { 207 auto_t_p[to_trans] = 1; 208 google.language.translate(to_trans, "", _tr_p.lang, function(result) { 209 if (!result.error) { 210 var segment_id = translated_id.substr(translated_id.lastIndexOf('_')+1); 211 // No longer need because now included in the ajax translate 212 //fix_page(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 213 ajax_translate(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 214 if (_tr_p.progress) { 215 done = togo - jQuery("."+_tr_p.prefix+'[source=""]').size(); 216 if (togo > 4) { 217 jQuery("#progress_bar").progressbar('value' , done/togo*100); 218 } 217 219 } 218 220 } 219 } 221 }); 222 } 223 }); 224 } 225 226 function confirm_close() { 227 jQuery('<div id="dial" title="Close without saving?"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>You have made a change to the translation. Are you sure you want to discard it?</p></div>').appendTo("body").dialog({ 228 bgiframe: true, 229 resizable: false, 230 height:140, 231 modal: true, 232 overlay: { 233 backgroundColor: '#000', 234 opacity: 0.5 235 }, 236 buttons: { 237 'Discard': function() { 238 jQuery("#"+_tr_p.prefix+"translation").data("edit", { 239 changed: false 240 }); 241 jQuery(this).dialog('close'); 242 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('close'); 243 }, 244 Cancel: function() { 245 jQuery(this).dialog('close'); 246 } 247 } 248 }); 249 } 250 251 //Open translation dialog 252 function translate_dialog(segment_id) { 253 jQuery("#"+_tr_p.prefix+"d-tabs").remove(); 254 jQuery('<div id="'+_tr_p.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body"); 255 jQuery("#"+_tr_p.prefix+"d-tabs").append('<ul/>').tabs({ 256 cache: true 257 }) 258 .tabs('add',"#"+_tr_p.prefix+"d-tabs-1",'Translate') 259 .tabs('add',_tr_p.post_url+'?tr_token_hist='+jQuery("#"+_tr_p.prefix + segment_id).attr('token')+'&lang='+_tr_p.lang,'History') 260 .css("text-align","left") 261 .css("padding",0) 262 .bind('tabsload', function(event, ui) { 263 //TODO, formatting here, not server side 264 jQuery("table",ui.panel).addClass("ui-widget ui-widget-content").css({ 265 'width' : '95%', 266 'padding' : '0' 220 267 }); 221 } 222 }); 223 } 224 225 function confirm_close() { 226 jQuery('<div id="dial" title="Close without saving?"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>You have made a change to the translation. Are you sure you want to discard it?</p></div>').appendTo("body").dialog({ 227 bgiframe: true, 228 resizable: false, 229 height:140, 230 modal: true, 231 overlay: { 232 backgroundColor: '#000', 233 opacity: 0.5 234 }, 235 buttons: { 236 'Discard': function() { 237 jQuery("#"+_tr_p.prefix+"translation").data("edit", { 238 changed: false 239 }); 240 jQuery(this).dialog('close'); 241 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('close'); 242 }, 243 Cancel: function() { 244 jQuery(this).dialog('close'); 245 } 246 } 247 }); 248 } 249 250 //Open translation dialog 251 function translate_dialog(segment_id) { 252 jQuery("#"+_tr_p.prefix+"d-tabs").remove(); 253 jQuery('<div id="'+_tr_p.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body"); 254 jQuery("#"+_tr_p.prefix+"d-tabs").append('<ul/>').tabs({ 255 cache: true 256 }) 257 .tabs('add',"#"+_tr_p.prefix+"d-tabs-1",'Translate') 258 .tabs('add',_tr_p.post_url+'?tr_token_hist='+jQuery("#"+_tr_p.prefix + segment_id).attr('token')+'&lang='+_tr_p.lang,'History') 259 .css("text-align","left") 260 .css("padding",0) 261 .bind('tabsload', function(event, ui) { 262 //TODO, formatting here, not server side 263 jQuery("table",ui.panel).addClass("ui-widget ui-widget-content").css({ 264 'width' : '95%', 265 'padding' : '0' 266 }); 267 //jQuery("table thead th:last",ui.panel).after("<th/>"); 268 jQuery("table thead tr",ui.panel).addClass("ui-widget-header"); 269 //jQuery("table tbody tr",ui.panel).append('<td/>'); 270 jQuery("table tbody td[source='1']",ui.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>'); 271 jQuery("table tbody td[source='0']",ui.panel).append('<span title="human" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-person"></span>'); 272 //jQuery("table tbody tr:first td:last",ui.panel).append('<span title="remove this translation" id="'+_tr_p.prefix+'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>'); 273 //jQuery("#"+_tr_p.prefix+"revert").click(function () { 274 //alert ('hi'); 275 //}); 276 }) 277 .bind('tabsselect', function(event, ui) { 278 // Change buttons 279 if (jQuery(ui.tab).text() == 'Translate') { 280 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', tButtons); 281 } else { 282 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', hButtons); 283 } 284 }) 285 .bind('dialogbeforeclose', function(event, ui) { 286 if(jQuery("#"+_tr_p.prefix+"translation").data("edit").changed) { 287 confirm_close(); 288 return false; 289 } 290 return true; 291 }); 292 // fix for templates messing with li 293 jQuery("#"+_tr_p.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside"); 294 jQuery("#"+_tr_p.prefix+"d-tabs-1").css("padding", "1px").append( 295 /*'<table><tr><td>'+*/ 296 '<form id="'+_tr_p.prefix+'form">' + 297 '<fieldset>' + 298 '<label for="original">Original Text</label>' + 299 '<textarea cols="80" row="3" name="original" id="'+_tr_p.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/>' + 300 '<label for="translation">Translate To</label>' + 301 '<textarea cols="80" row="3" name="translation" id="'+_tr_p.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/>' + 302 '</fieldset>' + 303 '</form>'/*+ 268 //jQuery("table thead th:last",ui.panel).after("<th/>"); 269 jQuery("table thead tr",ui.panel).addClass("ui-widget-header"); 270 //jQuery("table tbody tr",ui.panel).append('<td/>'); 271 jQuery("table tbody td[source='1']",ui.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>'); 272 jQuery("table tbody td[source='0']",ui.panel).append('<span title="human" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-person"></span>'); 273 //jQuery("table tbody tr:first td:last",ui.panel).append('<span title="remove this translation" id="'+_tr_p.prefix+'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>'); 274 //jQuery("#"+_tr_p.prefix+"revert").click(function () { 275 //alert ('hi'); 276 //}); 277 }) 278 .bind('tabsselect', function(event, ui) { 279 // Change buttons 280 if (jQuery(ui.tab).text() == 'Translate') { 281 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', tButtons); 282 } else { 283 jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', hButtons); 284 } 285 }) 286 .bind('dialogbeforeclose', function(event, ui) { 287 if(jQuery("#"+_tr_p.prefix+"translation").data("edit").changed) { 288 confirm_close(); 289 return false; 290 } 291 return true; 292 }); 293 // fix for templates messing with li 294 jQuery("#"+_tr_p.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside"); 295 jQuery("#"+_tr_p.prefix+"d-tabs-1").css("padding", "1px").append( 296 /*'<table><tr><td>'+*/ 297 '<form id="'+_tr_p.prefix+'form">' + 298 '<fieldset>' + 299 '<label for="original">Original Text</label>' + 300 '<textarea cols="80" row="3" name="original" id="'+_tr_p.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/>' + 301 '<label for="translation">Translate To</label>' + 302 '<textarea cols="80" row="3" name="translation" id="'+_tr_p.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/>' + 303 '</fieldset>' + 304 '</form>'/*+ 304 305 '</td><td style="width:32px">'+ 305 306 '<img src="/wp-content/plugins/transposh/img/knob/knobs/left.png"/>'+ … … 308 309 '<img src="/wp-content/plugins/transposh/img/knob/knobs/merge.png"/>'+ 309 310 '</td></tr></table>'*/); 310 /*jQuery("#smart").click(function() {311 /*jQuery("#smart").click(function() { 311 312 grabnext(segment_id); 312 313 });*/ 313 jQuery("#"+_tr_p.prefix+"d-tabs-1 label").css("display","block");314 jQuery("#"+_tr_p.prefix+"d-tabs-1 textarea.text").css({315 'margin-bottom':'12px',316 'width' : '95%',317 'padding' : '.4em'318 });319 jQuery("#"+_tr_p.prefix+"original").val(jQuery("#"+_tr_p.prefix + segment_id).attr('orig'));320 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).html());321 if (jQuery("#"+_tr_p.prefix + segment_id).attr('trans')) {322 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).attr('trans'));323 }324 jQuery("#"+_tr_p.prefix+"translation").data("edit", {325 changed: false326 });327 jQuery("#"+_tr_p.prefix+"translation").keyup(function(e){328 if (jQuery("#"+_tr_p.prefix + segment_id).text() != jQuery(this).val()) {329 jQuery(this).css("background","yellow");330 jQuery(this).data("edit", {331 changed: true332 });333 } else {334 jQuery(this).css("background","");335 jQuery(this).data("edit", {336 changed: false337 });338 }339 });340 var tButtons = {};341 //only add button is bing support is defined for the language (and we got some key)342 if (bing_langs.indexOf(_tr_p.lang) > -1 && _tr_p.msnkey != '') {343 //ar,zh-chs,zh-cht,nl,en,fr,de,he,it,ja,ko,pl,pt,ru,es344 tButtons['Suggest - Bing'] = function() {345 getbt();346 };347 }348 349 // Only add button if google supports said language350 if ( google_langs.indexOf(_tr_p.lang) > -1) {351 tButtons['Suggest - Google'] = function() {352 getgt();353 };354 }355 /* 'Next': function() {314 jQuery("#"+_tr_p.prefix+"d-tabs-1 label").css("display","block"); 315 jQuery("#"+_tr_p.prefix+"d-tabs-1 textarea.text").css({ 316 'margin-bottom':'12px', 317 'width' : '95%', 318 'padding' : '.4em' 319 }); 320 jQuery("#"+_tr_p.prefix+"original").val(jQuery("#"+_tr_p.prefix + segment_id).attr('orig')); 321 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).html()); 322 if (jQuery("#"+_tr_p.prefix + segment_id).attr('trans')) { 323 jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).attr('trans')); 324 } 325 jQuery("#"+_tr_p.prefix+"translation").data("edit", { 326 changed: false 327 }); 328 jQuery("#"+_tr_p.prefix+"translation").keyup(function(e){ 329 if (jQuery("#"+_tr_p.prefix + segment_id).text() != jQuery(this).val()) { 330 jQuery(this).css("background","yellow"); 331 jQuery(this).data("edit", { 332 changed: true 333 }); 334 } else { 335 jQuery(this).css("background",""); 336 jQuery(this).data("edit", { 337 changed: false 338 }); 339 } 340 }); 341 var tButtons = {}; 342 //only add button is bing support is defined for the language (and we got some key) 343 if (bing_langs.indexOf(_tr_p.lang) > -1 && _tr_p.msnkey != '') { 344 //ar,zh-chs,zh-cht,nl,en,fr,de,he,it,ja,ko,pl,pt,ru,es 345 tButtons['Suggest - Bing'] = function() { 346 getbt(); 347 }; 348 } 349 350 // Only add button if google supports said language 351 if ( google_langs.indexOf(_tr_p.lang) > -1) { 352 tButtons['Suggest - Google'] = function() { 353 getgt(); 354 }; 355 } 356 /* 'Next': function() { 356 357 alert(parseInt(segment_id)+1); 357 358 translate_dialog(parseInt(segment_id)+1); … … 361 362 //.next? .next all? 362 363 },*/ 363 tButtons['Ok'] = function() { 364 var translation = jQuery('#'+_tr_p.prefix+'translation').val(); 365 if(jQuery('#'+_tr_p.prefix+'translation').data("edit").changed) { 366 ajax_translate(translation,0,segment_id); 367 jQuery("#"+_tr_p.prefix+"translation").data("edit", { 368 changed: false 369 }); 370 } 371 jQuery(this).dialog('close'); 372 }; 373 //tButtons["beep"] = function() {alert(Microsoft.Translator.GetLanguages())}; 374 var hButtons = { 375 Close: function() { 364 tButtons['Ok'] = function() { 365 var translation = jQuery('#'+_tr_p.prefix+'translation').val(); 366 if(jQuery('#'+_tr_p.prefix+'translation').data("edit").changed) { 367 ajax_translate(translation,0,segment_id); 368 jQuery("#"+_tr_p.prefix+"translation").data("edit", { 369 changed: false 370 }); 371 } 376 372 jQuery(this).dialog('close'); 377 } 378 }; 379 jQuery("#"+_tr_p.prefix+"d-tabs").dialog({ 380 bgiframe: true, 381 modal: true, 382 //width: 'auto', 383 width: 500, 384 buttons: tButtons 385 }); 386 } 387 388 // We first try to avoid conflict with other frameworks 389 jQuery.noConflict(); 390 // the languages supported externally 391 // extracted using function above + he|zh-tw|pt that we know 392 google_langs = 'af|sq|ar|be|bg|ca|zh|zh-CN|zh-TW|hr|cs|da|nl|en|et|tl|fi|fr|gl|de|el|iw|hi|hu|is|id|ga|it|ja|ko|lv|lt|mk|ms|mt|no|fa|pl|pt-PT|ro|ru|sr|sk|sl|es|sw|sv|tl|th|tr|uk|vi|cy|yi|he|zh-tw|pt'; 393 // got this using Microsoft.Translator.GetLanguages() with added zh and zh-tw for our needs 394 bing_langs = 'ar,bg,zh-chs,zh-cht,cs,da,nl,en,fi,fr,de,el,he,it,ja,ko,pl,pt,ru,es,sv,th,zh,zh-tw'; 395 396 function loadLang() { 397 google.load("language", "1", { 398 "callback" : langLoaded 399 }); 400 } 401 402 jQuery(document).ready( 403 function() { 404 // this is the set_default_language function 405 // attach a function to the set_default_language link if its there 406 jQuery('#'+_tr_p.prefix+'setdeflang').click(function () { 407 jQuery.get( _tr_p.post_url+"?tr_cookie="+Math.random()); 408 jQuery(this).hide("slow"); 409 return false; 410 }) 411 412 // now lets check if auto translate is needed 413 translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"); 414 if (translationstats != undefined) { 415 possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases -(translationstats.meta_phrases - translationstats.meta_translated_phrases)); 416 now = new Date 417 // we'll only auto-translate and load the stuff if we either have more than 5 candidate translations, or more than one at 4am, and this language is supported... 418 if ((possibly_translateable > 5 || (now.getHours() == 4 && possibly_translateable > 0)) && google_langs.indexOf(_tr_p.lang) > -1) { 419 // TODO - FIX ME! (islands) 420 jQuery.ajaxSetup({ 421 cache: true 422 }); 423 // if we have a progress bar, we need to load the jqueryui before the auto translate, after the google was loaded, otherwise we can just go ahead 424 langLoaded = function() { 425 if (_tr_p.progress) { 426 jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 427 jQuery.xLazyLoader({ 428 js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 429 css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 430 success: function () { 431 do_auto_translate() 432 } 373 }; 374 //tButtons["beep"] = function() {alert(Microsoft.Translator.GetLanguages())}; 375 var hButtons = { 376 Close: function() { 377 jQuery(this).dialog('close'); 378 } 379 }; 380 jQuery("#"+_tr_p.prefix+"d-tabs").dialog({ 381 bgiframe: true, 382 modal: true, 383 //width: 'auto', 384 width: 500, 385 buttons: tButtons 386 }); 387 } 388 389 // We first try to avoid conflict with other frameworks 390 jQuery.noConflict(); 391 // the languages supported externally 392 // extracted using function above + he|zh-tw|pt that we know 393 google_langs = 'af|sq|ar|be|bg|ca|zh|zh-CN|zh-TW|hr|cs|da|nl|en|et|tl|fi|fr|gl|de|el|iw|hi|hu|is|id|ga|it|ja|ko|lv|lt|mk|ms|mt|no|fa|pl|pt-PT|ro|ru|sr|sk|sl|es|sw|sv|tl|th|tr|uk|vi|cy|yi|he|zh-tw|pt'; 394 // got this using Microsoft.Translator.GetLanguages() with added zh and zh-tw for our needs 395 bing_langs = 'ar,bg,zh-chs,zh-cht,cs,da,nl,en,fi,fr,de,el,he,it,ja,ko,pl,pt,ru,es,sv,th,zh,zh-tw'; 396 397 function loadLang() { 398 google.load("language", "1", { 399 "callback" : langLoaded 400 }); 401 } 402 403 jQuery(document).ready( 404 function() { 405 // this is the set_default_language function 406 // attach a function to the set_default_language link if its there 407 jQuery('#'+_tr_p.prefix+'setdeflang').click(function () { 408 jQuery.get( _tr_p.post_url+"?tr_cookie="+Math.random()); 409 jQuery(this).hide("slow"); 410 return false; 411 }) 412 413 // now lets check if auto translate is needed 414 translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"); 415 if (translationstats != undefined) { 416 possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases -(translationstats.meta_phrases - translationstats.meta_translated_phrases)); 417 now = new Date 418 // we'll only auto-translate and load the stuff if we either have more than 5 candidate translations, or more than one at 4am, and this language is supported... 419 if ((possibly_translateable > 5 || (now.getHours() == 4 && possibly_translateable > 0)) && google_langs.indexOf(_tr_p.lang) > -1) { 420 // TODO - FIX ME! (islands) 421 jQuery.ajaxSetup({ 422 cache: true 423 }); 424 // if we have a progress bar, we need to load the jqueryui before the auto translate, after the google was loaded, otherwise we can just go ahead 425 langLoaded = function() { 426 if (_tr_p.progress) { 427 jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 428 jQuery.xLazyLoader({ 429 js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 430 css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 431 success: function () { 432 do_auto_translate() 433 } 434 }); 433 435 }); 436 } else { 437 do_auto_translate() 438 } 439 }; 440 // we now start the chain that leads to auto-translate (with or without progress) 441 jQuery.getScript('http://www.google.com/jsapi?callback=loadLang'); 442 } 443 } 444 445 // this is the part when we have editor support 446 if (_tr_p.edit) { 447 // lets add the images 448 jQuery("."+_tr_p.prefix).each(function (i) { 449 var translated_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 450 jQuery(this).after('<span id="'+_tr_p.prefix+'img_'+translated_id+'" class="tr-icon" title="'+jQuery(this).attr('orig')+'"></span>'); 451 var img = jQuery('#'+_tr_p.prefix+'img_'+translated_id); 452 img.click(function () { 453 // if we detect that jQuery.ui is missing (TODO - check tabs - etal) we load it first 454 if (typeof jQuery.fn.tabs !== 'function') { 455 jQuery.ajaxSetup({ 456 cache: true 457 }); 458 jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 459 jQuery.xLazyLoader({ 460 js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 461 css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 462 success: function() { 463 translate_dialog(translated_id); 464 } 465 }); 466 }); 467 } else { 468 translate_dialog(translated_id); 469 } 470 return false; 471 }).css({ 472 'border':'0px', 473 'margin':'1px', 474 'padding':'0px' 475 }); 476 if (jQuery(this).attr('source') == '1') 477 img.addClass('tr-icon-yellow'); 478 else if (jQuery(this).attr('source') == '0') 479 img.addClass('tr-icon-green'); 480 // if the image is sourced from a hidden element - kinly "show" this 481 if (jQuery(this).attr('hidden') == 'y') { 482 img.css({ 483 'opacity':'0.6' 434 484 }); 435 } else {436 do_auto_translate()437 485 } 438 }; 439 // we now start the chain that leads to auto-translate (with or without progress) 440 jQuery.getScript('http://www.google.com/jsapi?callback=loadLang'); 441 } 442 } 443 444 // this is the part when we have editor support 445 if (_tr_p.edit) { 446 // lets add the images 447 jQuery("."+_tr_p.prefix).each(function (i) { 448 var translated_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 449 jQuery(this).after('<span id="'+_tr_p.prefix+'img_'+translated_id+'" class="tr-icon" title="'+jQuery(this).attr('orig')+'"></span>'); 450 var img = jQuery('#'+_tr_p.prefix+'img_'+translated_id); 451 img.click(function () { 452 // if we detect that jQuery.ui is missing (TODO - check tabs - etal) we load it first 453 if (typeof jQuery.ui == 'undefined') { 454 jQuery.ajaxSetup({ 455 cache: true 456 }); 457 jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 458 jQuery.xLazyLoader({ 459 js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 460 css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 461 success: function() { 462 translate_dialog(translated_id); 463 } 464 }); 465 }); 466 } else { 467 translate_dialog(translated_id); 468 } 469 return false; 470 }).css({ 471 'border':'0px', 472 'margin':'1px', 473 'padding':'0px' 474 }); 475 if (jQuery(this).attr('source') == '1') 476 img.addClass('tr-icon-yellow'); 477 else if (jQuery(this).attr('source') == '0') 478 img.addClass('tr-icon-green'); 479 // if the image is sourced from a hidden element - kinly "show" this 480 if (jQuery(this).attr('hidden') == 'y') { 481 img.css({ 482 'opacity':'0.6' 483 }); 484 } 485 }); 486 } 487 }); 486 }); 487 } 488 }); 489 })(); // end of closure
Note: See TracChangeset
for help on using the changeset viewer.
