- Timestamp:
- 02/02/2010 12:06:00 PM (2 years ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 3 edited
-
core/parser.php (modified) (1 diff)
-
js/transposh.js (modified) (6 diffs)
-
js/transposhedit.js (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/parser.php
r361 r376 421 421 // Use base64 encoding to make that when the page is translated (i.e. update_translation) we 422 422 // get back exactlly the same string without having the client decode/encode it in anyway. 423 $span = '<span class ="'.SPAN_PREFIX.'" id="'.SPAN_PREFIX.$this->segment_id.'" token="' . base64_url_encode($original_text)."\"source=\"$source\"";423 $span = '<span class ="'.SPAN_PREFIX.'" id="'.SPAN_PREFIX.$this->segment_id.'" data-token="' . base64_url_encode($original_text)."\" data-source=\"$source\""; 424 424 // those are needed for on the fly image creation / hidden elements translations 425 425 if ($this->is_edit_mode || $for_hidden_element) { 426 $span .= " orig=\"$original_text\"";426 $span .= " data-orig=\"$original_text\""; 427 427 if ($for_hidden_element) { 428 $span.= ' hidden="y"';428 $span.= ' data-hidden="y"'; 429 429 // hidden elements currently have issues figuring what they translated in the JS 430 430 if ($translated_text != null) { 431 $span.= " trans=\"$translated_text\"";431 $span.= " data-trans=\"$translated_text\""; 432 432 } 433 433 } -
trunk/WordPress/plugin/transposh/js/transposh.js
r373 r376 48 48 var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1), 49 49 img = $("#" + t_jp_prefix + "img_" + img_segment_id); 50 $("#" + t_jp_prefix + img_segment_id).attr(' source', 1); // source is 150 $("#" + t_jp_prefix + img_segment_id).attr('data-source', 1); // source is 1 51 51 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green').addClass('tr-icon-yellow'); 52 52 }; 53 53 54 54 // rewrite text for all matching items at once 55 $("*[ token='" + token + "'][hidden!='y']")55 $("*[data-token='" + token + "'][data-hidden!='y']") 56 56 .html(translation) 57 57 .each(fix_image); 58 58 59 59 // TODO - FIX hidden elements too (need to update father's title) 60 $("*[ token='" + token + "'][hidden='y']")61 .attr(' trans', translation)60 $("*[data-token='" + token + "'][data-hidden='y']") 61 .attr('data-trans', translation) 62 62 .each(fix_image); 63 63 } … … 92 92 // We are pre-accounting the progress bar here - which is not very nice 93 93 //if (source > 0) { 94 done_posted += $("*[ token='" + tokens[i] + "']").size();94 done_posted += $("*[data-token='" + tokens[i] + "']").size(); 95 95 //} 96 96 } … … 137 137 // auto_translated_previously... 138 138 var auto_translated_phrases = [], binglang = t_jp.lang; 139 $("." + t_jp_prefix + '[ source=""]').each(function (i) {139 $("." + t_jp_prefix + '[data-source=""]').each(function (i) { 140 140 // not needed! 141 141 //var translated_id = $(this).attr('id'), 142 var token = $(this).attr(' token'),142 var token = $(this).attr('data-token'), 143 143 //alert(translated_id); 144 144 // we only have orig if we have some translation,? 145 to_trans = $(this).attr(' orig');145 to_trans = $(this).attr('data-orig'); 146 146 if (to_trans === undefined) { 147 147 to_trans = $(this).html(); … … 159 159 Microsoft.Translator.translate(to_trans, "", binglang, function (translation) { 160 160 ajax_translate(token, $("<div>" + translation + "</div>").text()); 161 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[ source=""]').size()) / possibly_translateable * 100);161 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[data-source=""]').size()) / possibly_translateable * 100); 162 162 //$('#' + progressbar_id).progressbar('value', (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 163 163 }); … … 177 177 //fix_page($("<div>" + result.translation + "</div>").text(), 1, segment_id); 178 178 // ???? 179 //to_trans = $(this).attr(' orig');179 //to_trans = $(this).attr('data-orig'); 180 180 ajax_translate(token, $("<div>" + result.translation + "</div>").text()); 181 181 // update the regular progress bar 182 182 // done = possibly_translateable - $("." + t_jp_prefix + '[source=""]').size(); 183 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[ source=""]').size()) / possibly_translateable * 100);183 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[data-source=""]').size()) / possibly_translateable * 100); 184 184 //$('#' + progressbar_id).progressbar('value', (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 185 185 } … … 231 231 //if (translationstats !== undefined) { 232 232 //possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases - (translationstats.meta_phrases - translationstats.meta_translated_phrases)); 233 possibly_translateable = $("." + t_jp_prefix + '[ source=""]').size();233 possibly_translateable = $("." + t_jp_prefix + '[data-source=""]').size(); 234 234 235 235 now = new Date(); -
trunk/WordPress/plugin/transposh/js/transposhedit.js
r370 r376 16 16 */ 17 17 // source - 0 is human, 1 is gt - 2 and higher reserved for future engines 18 /*global Date, Math, Microsoft, alert, clearTimeout, document, google, jQuery, setTimeout, t_jp, window */18 /*global Date, Math, Microsoft, alert, clearTimeout, document, google, $, setTimeout, t_jp, window */ 19 19 // fetch translation from google translate... 20 (function ( ) { // closure20 (function ($) { // closure 21 21 var loadLang, langLoaded; 22 22 //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', … … 27 27 //reset to the original content - the unescaped version if translation is empty 28 28 // TODO! 29 if ( jQuery.trim(translation).length === 0) {30 translation = jQuery("[token='" + token + "']").attr('orig');29 if ($.trim(translation).length === 0) { 30 translation = $("[data-token='" + token + "']").attr('data-orig'); 31 31 } 32 32 33 33 var fix_image = function () { // handle the image changes 34 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_') + 1),35 img = jQuery("#" + t_jp.prefix + "img_" + img_segment_id);36 jQuery("#" + t_jp.prefix + img_segment_id).attr('source', 0); // source is 0 human34 var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1), 35 img = $("#" + t_jp.prefix + "img_" + img_segment_id); 36 $("#" + t_jp.prefix + img_segment_id).attr('data-source', 0); // source is 0 human 37 37 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green').addClass('tr-icon-green'); 38 // TODO if ( jQuery.trim(translation).length !== 0) { remove green on zero length?38 // TODO if ($.trim(translation).length !== 0) { remove green on zero length? 39 39 40 40 }; 41 41 // rewrite text for all matching items at once 42 jQuery("*[token='" + token + "'][hidden!='y']")42 $("*[data-token='" + token + "'][data-hidden!='y']") 43 43 .html(translation) 44 44 .each(fix_image); 45 45 46 46 // FIX hidden elements too (need to update father's title) 47 jQuery("*[token='" + token + "'][hidden='y']")48 .attr(' trans', translation)47 $("*[data-token='" + token + "'][data-hidden='y']") 48 .attr('data-trans', translation) 49 49 .each(fix_image); 50 50 } … … 65 65 // We are pre-accounting the progress bar here - which is not very nice 66 66 /*TODO think!!!! if (source > 0) { 67 done_p += jQuery("*[token='" + token + "']").size();67 done_p += $("*[token='" + token + "']").size(); 68 68 }*/ 69 jQuery.ajax({69 $.ajax({ 70 70 type: "POST", 71 71 url: t_jp.post_url, … … 75 75 /* THINK if (t_jp.progress) { 76 76 if (togo > 4 && source > 0) { 77 jQuery("#progress_bar2").progressbar('value', done_p / togo * 100);77 $("#progress_bar2").progressbar('value', done_p / togo * 100); 78 78 } 79 79 … … 98 98 getgt(); 99 99 }; 100 jQuery.xLazyLoader({100 $.xLazyLoader({ 101 101 // js: 'http://www.google.com/jsapi?callback=loadLang' 102 102 js: 'http://www.google.com/jsapi', … … 104 104 }); 105 105 } else { 106 jQuery(":button:contains('Suggest - Google')").attr("disabled", "disabled").addClass("ui-state-disabled");107 google.language.translate( jQuery("#" + t_jp.prefix + "original").val(), "", t_jp.lang, function (result) {106 $(":button:contains('Suggest - Google')").attr("disabled", "disabled").addClass("ui-state-disabled"); 107 google.language.translate($("#" + t_jp.prefix + "original").val(), "", t_jp.lang, function (result) { 108 108 if (!result.error) { 109 jQuery("#" + t_jp.prefix + "translation").val(jQuery("<div>" + result.translation + "</div>").text())109 $("#" + t_jp.prefix + "translation").val($("<div>" + result.translation + "</div>").text()) 110 110 .keyup(); 111 111 } … … 118 118 { 119 119 if (typeof Microsoft === 'undefined') { 120 jQuery.xLazyLoader({120 $.xLazyLoader({ 121 121 js: 'http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=' + t_jp.msnkey, 122 122 success: function () { … … 126 126 127 127 } else { 128 jQuery(":button:contains('Suggest - Bing')").attr("disabled", "disabled").addClass("ui-state-disabled");128 $(":button:contains('Suggest - Bing')").attr("disabled", "disabled").addClass("ui-state-disabled"); 129 129 var binglang = t_jp.lang; 130 130 if (binglang === 'zh') { … … 135 135 } 136 136 try { 137 Microsoft.Translator.translate( jQuery("#" + t_jp.prefix + "original").val(), "", binglang, function (translation) {138 jQuery("#" + t_jp.prefix + "translation").val(jQuery("<div>" + translation + "</div>").text())137 Microsoft.Translator.translate($("#" + t_jp.prefix + "original").val(), "", binglang, function (translation) { 138 $("#" + t_jp.prefix + "translation").val($("<div>" + translation + "</div>").text()) 139 139 .keyup(); 140 140 }); … … 147 147 148 148 function confirm_close() { 149 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({149 $('<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({ 150 150 bgiframe: true, 151 151 resizable: false, … … 158 158 buttons: { 159 159 'Discard': function () { 160 jQuery("#" + t_jp.prefix + "translation").data("edit", {160 $("#" + t_jp.prefix + "translation").data("edit", { 161 161 changed: false 162 162 }); 163 jQuery(this).dialog('close');164 jQuery("#" + t_jp.prefix + "d-tabs").dialog('close');163 $(this).dialog('close'); 164 $("#" + t_jp.prefix + "d-tabs").dialog('close'); 165 165 }, 166 166 Cancel: function () { 167 jQuery(this).dialog('close');167 $(this).dialog('close'); 168 168 } 169 169 } … … 197 197 },*/ 198 198 tButtons.Ok = function () { 199 var translation = jQuery('#' + t_jp.prefix + 'translation').val(),200 token = jQuery("#" + t_jp.prefix + segment_id).attr('token');201 if ( jQuery('#' + t_jp.prefix + 'translation').data("edit").changed) {199 var translation = $('#' + t_jp.prefix + 'translation').val(), 200 token = $("#" + t_jp.prefix + segment_id).attr('data-token'); 201 if ($('#' + t_jp.prefix + 'translation').data("edit").changed) { 202 202 ajax_translate_human(token, translation); 203 jQuery("#" + t_jp.prefix + "translation").data("edit", {203 $("#" + t_jp.prefix + "translation").data("edit", { 204 204 changed: false 205 205 }); 206 206 } 207 jQuery(this).dialog('close');207 $(this).dialog('close'); 208 208 }; 209 209 //tButtons["beep"] = function () {alert(Microsoft.Translator.GetLanguages())}; 210 210 hButtons = { 211 211 Close: function () { 212 jQuery(this).dialog('close');212 $(this).dialog('close'); 213 213 } 214 214 }; 215 215 216 jQuery("#" + t_jp.prefix + "d-tabs").remove();217 jQuery('<div id="' + t_jp.prefix + 'd-tabs" title="Edit Translation"/>').appendTo("body");218 jQuery("#" + t_jp.prefix + "d-tabs").append('<ul/>').tabs({216 $("#" + t_jp.prefix + "d-tabs").remove(); 217 $('<div id="' + t_jp.prefix + 'd-tabs" title="Edit Translation"/>').appendTo("body"); 218 $("#" + t_jp.prefix + "d-tabs").append('<ul/>').tabs({ 219 219 cache: true 220 220 }) 221 221 .tabs('add', "#" + t_jp.prefix + "d-tabs-1", 'Translate') 222 .tabs('add', t_jp.post_url + '?tr_token_hist=' + jQuery("#" + t_jp.prefix + segment_id).attr('token') + '&lang=' + t_jp.lang, 'History')222 .tabs('add', t_jp.post_url + '?tr_token_hist=' + $("#" + t_jp.prefix + segment_id).attr('data-token') + '&lang=' + t_jp.lang, 'History') 223 223 .css("text-align", "left") 224 224 .css("padding", 0) 225 225 .bind('tabsload', function (event, ui) { 226 226 //TODO, formatting here, not server side 227 jQuery("table", ui.panel).addClass("ui-widget ui-widget-content").css({227 $("table", ui.panel).addClass("ui-widget ui-widget-content").css({ 228 228 'width' : '95%', 229 229 'padding' : '0' 230 230 }); 231 // jQuery("table thead th:last",ui.panel).after("<th/>");232 jQuery("table thead tr", ui.panel).addClass("ui-widget-header");233 // jQuery("table tbody tr", ui.panel).append('<td/>');234 jQuery("table tbody td[source='2']", ui.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');235 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>');236 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>');237 // jQuery("table tbody tr:first td:last", ui.panel).append('<span title="remove this translation" id="' + t_jp.prefix + 'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>');238 // jQuery("#" + t_jp.prefix + "revert").click(function () {231 //$("table thead th:last",ui.panel).after("<th/>"); 232 $("table thead tr", ui.panel).addClass("ui-widget-header"); 233 //$("table tbody tr", ui.panel).append('<td/>'); 234 $("table tbody td[source='2']", ui.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>'); 235 $("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>'); 236 $("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>'); 237 //$("table tbody tr:first td:last", ui.panel).append('<span title="remove this translation" id="' + t_jp.prefix + 'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>'); 238 //$("#" + t_jp.prefix + "revert").click(function () { 239 239 //alert ('hi'); 240 240 //}); … … 242 242 .bind('tabsselect', function (event, ui) { 243 243 // Change buttons 244 if ( jQuery(ui.tab).text() === 'Translate') {245 jQuery("#" + t_jp.prefix + "d-tabs").dialog('option', 'buttons', tButtons);244 if ($(ui.tab).text() === 'Translate') { 245 $("#" + t_jp.prefix + "d-tabs").dialog('option', 'buttons', tButtons); 246 246 } else { 247 jQuery("#" + t_jp.prefix + "d-tabs").dialog('option', 'buttons', hButtons);247 $("#" + t_jp.prefix + "d-tabs").dialog('option', 'buttons', hButtons); 248 248 } 249 249 }) 250 250 .bind('dialogbeforeclose', function (event, ui) { 251 if ( jQuery("#" + t_jp.prefix + "translation").data("edit").changed) {251 if ($("#" + t_jp.prefix + "translation").data("edit").changed) { 252 252 confirm_close(); 253 253 return false; … … 256 256 }); 257 257 // fix for templates messing with li 258 jQuery("#" + t_jp.prefix + "d-tabs li").css("list-style-type", "none").css("list-style-position", "outside");259 jQuery("#" + t_jp.prefix + "d-tabs-1").css("padding", "1px").append(258 $("#" + t_jp.prefix + "d-tabs li").css("list-style-type", "none").css("list-style-position", "outside"); 259 $("#" + t_jp.prefix + "d-tabs-1").css("padding", "1px").append( 260 260 /*'<table><tr><td>'+*/ 261 261 '<form id="' + t_jp.prefix + 'form">' + … … 273 273 '<img src="/wp-content/plugins/transposh/img/knob/knobs/merge.png"/>'+ 274 274 '</td></tr></table>'*/); 275 /* jQuery("#smart").click(function () {275 /*$("#smart").click(function () { 276 276 grabnext(segment_id); 277 277 });*/ 278 jQuery("#" + t_jp.prefix + "d-tabs-1 label").css("display", "block");279 jQuery("#" + t_jp.prefix + "d-tabs-1 textarea.text").css({278 $("#" + t_jp.prefix + "d-tabs-1 label").css("display", "block"); 279 $("#" + t_jp.prefix + "d-tabs-1 textarea.text").css({ 280 280 'margin-bottom': '12px', 281 281 'width' : '95%', 282 282 'padding' : '.4em' 283 283 }); 284 jQuery("#" + t_jp.prefix + "original").val(jQuery("#" + t_jp.prefix + segment_id).attr('orig'));285 jQuery("#" + t_jp.prefix + "translation").val(jQuery("#" + t_jp.prefix + segment_id).html());286 if ( jQuery("#" + t_jp.prefix + segment_id).attr('trans')) {287 jQuery("#" + t_jp.prefix + "translation").val(jQuery("#" + t_jp.prefix + segment_id).attr('trans'));288 } 289 jQuery("#" + t_jp.prefix + "translation").data("edit", {284 $("#" + t_jp.prefix + "original").val($("#" + t_jp.prefix + segment_id).attr('data-orig')); 285 $("#" + t_jp.prefix + "translation").val($("#" + t_jp.prefix + segment_id).html()); 286 if ($("#" + t_jp.prefix + segment_id).attr('data-trans')) { 287 $("#" + t_jp.prefix + "translation").val($("#" + t_jp.prefix + segment_id).attr('data-trans')); 288 } 289 $("#" + t_jp.prefix + "translation").data("edit", { 290 290 changed: false 291 291 }); 292 jQuery("#" + t_jp.prefix + "translation").keyup(function (e) {293 if ( jQuery("#" + t_jp.prefix + segment_id).text() !== jQuery(this).val()) {294 jQuery(this).css("background", "yellow");295 jQuery(this).data("edit", {292 $("#" + t_jp.prefix + "translation").keyup(function (e) { 293 if ($("#" + t_jp.prefix + segment_id).text() !== $(this).val()) { 294 $(this).css("background", "yellow"); 295 $(this).data("edit", { 296 296 changed: true 297 297 }); 298 298 } else { 299 jQuery(this).css("background", "");300 jQuery(this).data("edit", {299 $(this).css("background", ""); 300 $(this).data("edit", { 301 301 changed: false 302 302 }); 303 303 } 304 304 }); 305 jQuery("#" + t_jp.prefix + "d-tabs").dialog({305 $("#" + t_jp.prefix + "d-tabs").dialog({ 306 306 bgiframe: true, 307 307 modal: true, … … 314 314 315 315 // lets add the images 316 jQuery("." + t_jp.prefix).each(function (i) {317 var translated_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_') + 1), img;318 jQuery(this).after('<span id="' + t_jp.prefix + 'img_' + translated_id + '" class="tr-icon" title="' + jQuery(this).attr('orig') + '"></span>');319 img = jQuery('#' + t_jp.prefix + 'img_' + translated_id);316 $("." + t_jp.prefix).each(function (i) { 317 var translated_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1), img; 318 $(this).after('<span id="' + t_jp.prefix + 'img_' + translated_id + '" class="tr-icon" title="' + $(this).attr('data-orig') + '"></span>'); 319 img = $('#' + t_jp.prefix + 'img_' + translated_id); 320 320 img.click(function () { 321 // if we detect that jQuery.ui is missing (TODO - check tabs - etal) we load it first322 if (typeof jQuery.fn.tabs !== 'function') {323 jQuery.ajaxSetup({321 // if we detect that $.ui is missing (TODO - check tabs - etal) we load it first 322 if (typeof $.fn.tabs !== 'function') { 323 $.ajaxSetup({ 324 324 cache: true 325 325 }); 326 jQuery.getScript(t_jp.plugin_url + '/js/lazy.js', function () {327 jQuery.xLazyLoader({328 js: 'http://ajax.googleapis.com/ajax/libs/ jqueryui/1.7.2/jquery-ui.min.js',329 css: 'http://ajax.googleapis.com/ajax/libs/ jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css',326 $.getScript(t_jp.plugin_url + '/js/lazy.js', function () { 327 $.xLazyLoader({ 328 js: 'http://ajax.googleapis.com/ajax/libs/$ui/1.7.2/$-ui.min.js', 329 css: 'http://ajax.googleapis.com/ajax/libs/$ui/1.7.2/themes/ui-lightness/$-ui.css', 330 330 success: function () { 331 331 translate_dialog(translated_id); … … 342 342 'padding': '0px' 343 343 }); 344 if ( jQuery(this).attr('source') === '0') {344 if ($(this).attr('data-source') === '0') { 345 345 img.addClass('tr-icon-green'); 346 346 } 347 else if ( jQuery(this).attr('source')) {347 else if ($(this).attr('data-source')) { 348 348 img.addClass('tr-icon-yellow'); 349 349 } 350 350 // if the image is sourced from a hidden element - kindly "show" this 351 if ( jQuery(this).attr('hidden') === 'y') {351 if ($(this).attr('data-hidden') === 'y') { 352 352 img.css({ 353 353 'opacity': '0.6' … … 355 355 } 356 356 }); 357 }( )); // end of closure357 }(jQuery)); // end of closure
Note: See TracChangeset
for help on using the changeset viewer.
