Changeset 386
- Timestamp:
- 03/04/2010 02:12:58 AM (6 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 5 edited
-
js/transposhadmin.js (modified) (4 diffs)
-
js/transposhcontrol.js (modified) (2 diffs)
-
wp/transposh_admin.php (modified) (7 diffs)
-
wp/transposh_ajax.php (modified) (1 diff)
-
wp/transposh_postpublish.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/js/transposhadmin.js
r362 r386 1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 1 /* Copyright © 2009-2010 Transposh Team (website : http://transposh.org) 2 * 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation; either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 4 16 */ 5 17 … … 36 48 jQuery.ajax({ 37 49 type: "POST", 38 url: t ransposh_params.post_url,50 url: t_jp.post_url, 39 51 data: data, 40 52 success: function() { … … 50 62 }, 200); // wait 200 ms... 51 63 } 52 /*53 64 54 */ 55 //to run at start 56 jQuery.noConflict(); 57 google.load("language", "1"); 58 59 //read parameters 60 var transposh_params = new Array(); 61 var ext_langs = 'he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi'; 62 jQuery("script[src*='transposhadmin.js']").each(function (j) { 63 var query_string = unescape(this.src.substring(this.src.indexOf('?')+1)); 64 var parms = query_string.split('&'); 65 for (var i=0; i<parms.length; i++) { 66 var pos = parms[i].indexOf('='); 67 if (pos > 0) { 68 var key = parms[i].substring(0,pos); 69 var val = parms[i].substring(pos+1); 70 transposh_params[key] = val; 71 } 72 } 73 }); 74 75 jQuery(document).ready(function() { 76 //var count = 0; 65 function translate_post(postid) { 66 // count = 0; 77 67 var p_count = 0; 78 68 var prev_name=''; 79 69 var l_count = 0; 80 81 jQuery.getJSON(t ransposh_params.post_url+"?tr_phrases_post=y&post="+transposh_params.post+"&random="+Math.random(), function(json) { // need to add random to avoid getting cached!70 jQuery("#tr_loading").data("done",false); 71 jQuery.getJSON(t_jp.post_url+"?tr_phrases_post=y&post="+postid+"&random="+Math.random(), function(json) { // need to add random to avoid getting cached! 82 72 // if we got no results than seems like we have nothing to translate 83 if (json == null) { 84 jQuery("#tr_loading").replaceWith('Nothing left to translate'); 73 jQuery("#tr_translate_title").html("Translating post: "+json.posttitle); 74 if (json.length === undefined) { 75 jQuery("#tr_loading").html('Nothing left to translate'); 76 jQuery("#tr_loading").data("done",true); 85 77 return; 86 78 } 87 79 // create progress bars 88 jQuery("#tr_loading"). replaceWith('Translating<br/>Phrase: <span id="p"></span><div id="progress_bar"/>Target lanaguage: <span id="l"></span><div id="progress_bar2"/><span id="r"></span>')80 jQuery("#tr_loading").html('Translating<br/>Phrase: <span id="p"></span><div id="progress_bar"/>Target lanaguage: <span id="l"></span><div id="progress_bar2"/><span id="r"></span>'); 89 81 jQuery("#progress_bar").progressbar({ 90 82 value:0 … … 97 89 jQuery.each(val.l, function(id,lang) { 98 90 // if (count <1000) { 99 google.language.translate(name, "", lang, function(result) { 100 if (!result.error) { 101 // No longer need because now included in the ajax translate 102 if (prev_name != name) { 103 prev_name = name; 104 l_count = 0; 105 p_count++; 106 } 107 jQuery("#progress_bar").progressbar('value' , p_count/json.length*100); 108 l_count++; 109 jQuery("#progress_bar2").progressbar('value' , l_count/val.l.length*100); 110 jQuery('#p').text(jQuery("<div>"+name+"</div>").text()); 111 jQuery('#l').text(lang); 112 jQuery('#r').text(jQuery("<div>"+result.translation+"</div>").text()); 113 ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 91 google.language.translate(name, "", lang, function(result) { 92 if (!result.error) { 93 // No longer need because now included in the ajax translate 94 if (prev_name != name) { 95 prev_name = name; 96 l_count = 0; 97 p_count++; 114 98 } 115 }); 116 //count++; 117 //} 99 jQuery("#progress_bar").progressbar('value' , p_count/json.length*100); 100 l_count++; 101 jQuery("#progress_bar2").progressbar('value' , l_count/val.l.length*100); 102 jQuery('#p').text(jQuery("<div>"+name+"</div>").text()); 103 jQuery('#l').text(lang); 104 jQuery('#r').text(jQuery("<div>"+result.translation+"</div>").text()); 105 if (p_count === json.length && l_count === val.l.length) 106 jQuery("#tr_loading").data("done",true); 107 ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 108 } 109 }); 110 //count++; 111 //} 118 112 }); 119 113 }); 120 114 }); 115 } 116 117 google.load("language", "1"); 118 119 jQuery(document).ready(function() { 120 if (t_jp.post) { 121 translate_post(t_jp.post); 122 } 121 123 }); -
trunk/WordPress/plugin/transposh/js/transposhcontrol.js
r346 r386 16 16 */ 17 17 18 /*'function chbx_change(lang)'. 19 '{'. 20 'jQuery("#"+lang+"_edit").attr("checked",jQuery("#"+lang+"_view").attr("checked"))'. 21 '}'. 22 'jQuery(document).ready(function() {'. 23 'jQuery("#tr_anon").click(function() {'. 24 'if (jQuery("#tr_anon").attr("checked")) {'. 25 'jQuery(".tr_editable").css("display","none");'. 26 '} else {'. 27 'jQuery(".tr_editable").css("display","");'. 28 '}'. 29 '});'. 30 '});'. 31 '</script>';*/ 18 //(function ($) { // closure 32 19 jQuery(function() { 33 20 // clicking anonymous will make translatables active … … 134 121 }); 135 122 123 // backup button 124 jQuery("#transposh-backup").click(function () { 125 jQuery.get(t_jp.post_url + "?backup=" + Math.random()); 126 return false; 127 }); 128 129 // translate all button 130 do_translate_all = function () { 131 jQuery("#progress_bar_all").progressbar({ 132 value:0 133 }); 134 stop_translate_var = false; 135 // while there is a next 136 // get next post to translate 137 //var offset = "0"; 138 jQuery("#tr_loading").data("done",true); 139 jQuery.ajaxSetup({ 140 cache: false 141 }); 142 jQuery.getJSON(t_jp.post_url,{ 143 translate_all:"y" 144 }, function (data) { 145 dotimer = function(a) { 146 clearTimeout(timer2); 147 //console.log(a); 148 //console.log(jQuery("#tr_loading").data("done")); 149 if (jQuery("#tr_loading").data("done") || jQuery("#tr_loading").data("attempt")>4) { 150 jQuery("#progress_bar_all").progressbar('value' , (a+1)/data.length*100); 151 jQuery("#tr_loading").data("attempt",0); 152 translate_post(data[a]); 153 //console.log(jQuery("#tr_loading").data("done")); 154 //console.log("done translate" + a); 155 if (data[a] && !stop_translate_var) { 156 //console.log("trigger translation of " +a); 157 timer2 = setTimeout(function() { 158 dotimer(a+1) 159 },1000); 160 } 161 } else { 162 //console.log("waiting for translation to finish 60 seconds"); 163 jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1); 164 timer2 = setTimeout(function() { 165 dotimer(a) 166 },60000); 167 } 168 } 169 timer2 = setTimeout(function() { 170 dotimer(0) 171 },0); 172 }); 173 jQuery("#transposh-translate").text("Stop translate") 174 jQuery("#transposh-translate").click(stop_translate); 175 return false; 176 } 177 178 stop_translate = function() { 179 clearTimeout(timer2); 180 stop_translate_var = true; 181 jQuery("#transposh-translate").text("Translate All Now") 182 jQuery("#transposh-translate").click(do_translate_all); 183 return false; 184 } 185 186 jQuery("#transposh-translate").click(do_translate_all); 187 136 188 }); 189 //}(jQuery)); // end of closure -
trunk/WordPress/plugin/transposh/wp/transposh_admin.php
r364 r386 86 86 logger($_POST['languages']); 87 87 foreach($_POST['languages'] as $code => $lang) { 88 list ($langcode, $viewable, $translateable) = explode(",",$lang);88 list ($langcode, $viewable, $translateable) = explode(",",$lang); 89 89 $sorted_langs[$langcode] = $langcode; 90 90 if($viewable) { … … 162 162 wp_enqueue_script('jquery-ui-droppable'); 163 163 wp_enqueue_script("transposh_control",$this->transposh->transposh_plugin_url."/js/transposhcontrol.js",array(),TRANSPOSH_PLUGIN_VER, true); 164 wp_localize_script("transposh_control","t_jp",array( 165 'post_url' => $this->transposh->post_url/*, 166 'plugin_url' => $this->transposh_plugin_url, 167 'edit' => ($this->edit_mode? '1' : ''), 168 //'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''), 169 'lang' => $this->target_language, 170 // those two options show if the script can support said engines 171 'msn' => (in_array($this->target_language,$GLOBALS['bing_languages']) && $this->options->get_msn_key() ? '1' : ''), 172 'google' => (in_array($this->target_language,$GLOBALS['google_languages']) ? '1' : ''), 173 'prefix' => SPAN_PREFIX, 174 'msnkey'=>$this->options->get_msn_key(), 175 'preferred'=> $this->options->get_preferred_translator(), 176 'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '')*/ 177 // 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};' 178 )); 179 wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',true); 180 wp_enqueue_script("transposh_admin",$this->transposh->transposh_plugin_url."/js/transposhadmin.js",array(),TRANSPOSH_PLUGIN_VER, true); 181 wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0'); 182 wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',true); 183 164 184 165 185 //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore … … 168 188 add_meta_box('transposh-sidebox-news', 'Plugin news', array(&$this, 'on_sidebox_news_content'), $this->pagehook, 'side', 'core'); 169 189 add_meta_box('transposh-sidebox-stats', 'Plugin stats', array(&$this, 'on_sidebox_stats_content'), $this->pagehook, 'side', 'core'); 190 add_meta_box('transposh-sidebox-translate', 'Translate all', array(&$this, 'on_sidebox_translate_content'), $this->pagehook, 'side', 'core'); 170 191 add_meta_box('transposh-contentbox-languages', 'Supported languages', array(&$this, 'on_contentbox_languages_content'), $this->pagehook, 'normal', 'core'); 171 192 add_meta_box('transposh-contentbox-translation', 'Translation settings', array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core'); … … 302 323 function on_sidebox_stats_content($data) { 303 324 $this->transposh->database->db_stats(); 325 } 326 327 function on_sidebox_translate_content($data) { 328 echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>'; 329 echo '<div id="tr_loading" style="margin: 0 0 10px 0">Translate by clicking the button below</div>'; 330 echo '<a id="transposh-translate" href="'.$this->transposh->post_url.'?translate_all&offset=1" onclick="return false;" class="button">Translate All Now</a><br/>'; 331 //get_posts 304 332 } 305 333 … … 359 387 .display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname,$this->transposh->options->get_widget_css_flags()) 360 388 .'<input type="hidden" name="languages[]" value="'. $this->transposh->options->get_default_language() .'" />' 361 .' <span class="langname">'.$langorigname.'</span><span class="langname hidden">'.$langname.'</span></li>';389 .' <span class="langname">'.$langorigname.'</span><span class="langname hidden">'.$langname.'</span></li>'; 362 390 echo '</ul></div>'; 363 391 // list of languages … … 428 456 } 429 457 430 function on_contentbox_auto_translation_content($data) {458 function on_contentbox_auto_translation_content($data) { 431 459 432 460 /* … … 498 526 'This will redirect the first page accessed in the session to the same page with the detected language.'; 499 527 500 /* WIP2528 /* WIP2 501 529 echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>';*/ 502 530 } 503 531 504 532 function on_contentbox_community_content($data) { 533 /* echo '<a tabindex="4" id="transposh-backup" href="/wp-admin/post-new.php?preview=true" class="button">Do Backup Now</a><br/>'; 534 // echo "<p id=\"backup\">Do backup.</p>"; 535 echo 'Service Key: <input type="text" size="32" class="regular-text" value="'.$this->transposh->options->get_transposh_key().'" id="'.TRANSPOSH_KEY.'" name="'.TRANSPOSH_KEY.'"/>'; 536 echo ' 537 <script type="text/javascript"> 538 //<![CDATA[ 539 jQuery(document).ready( function($) { 540 // close postboxes that should be closed 541 $("#backup").click(function () { 542 $.get("'.$this->transposh->post_url.'?backup=" + Math.random()); 543 //alert ("hi"); 544 }); 545 }); 546 //]]> 547 </script>';*/ 505 548 echo "<p>This space is reserved for the coming community features of Transposh that will help you find translators to help with your site.</p>"; 506 549 } -
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r371 r386 81 81 } 82 82 } 83 // Start full translation 84 elseif (isset($_GET['translate_all'])) { 85 // get all ids in need of translation 86 $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type='page' OR post_type='post' ORDER BY ID DESC"); 87 // only high capabilities users can... 88 if (!current_user_can('edit_post',$page_ids[0])) return; 89 echo json_encode($page_ids); 90 } 91 // Start backup on demand 92 /*elseif (isset($_GET['backup'])) { 93 $my_transposh_backup = new transposh_backup($my_transposh_plugin); 94 $my_transposh_backup->do_backup(); 95 }*/ 96 83 97 ?> -
trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php
r346 r386 16 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 17 * 18 */18 */ 19 19 20 20 /* 21 21 * Provides the side widget in the page/edit pages which will do translations 22 */22 */ 23 23 24 24 /** … … 40 40 if ($this->transposh->options->get_enable_auto_post_translate()) { 41 41 add_action('edit_post',array(&$this, 'on_edit')); 42 // add_action('publish_post',array(&$this, 'on_publish'));42 // add_action('publish_post',array(&$this, 'on_publish')); 43 43 add_action('admin_menu', array(&$this, 'on_admin_menu')); 44 44 } … … 55 55 if ($_GET['justedited']) { 56 56 wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',true); 57 wp_enqueue_script("transposh","{$this->transposh->transposh_plugin_url}/js/transposhadmin.js?post_url={$this->transposh->post_url}&post={$_GET['post']}",array("jquery"),TRANSPOSH_PLUGIN_VER,true); 57 wp_enqueue_script("transposh","{$this->transposh->transposh_plugin_url}/js/transposhadmin.js",array("jquery"),TRANSPOSH_PLUGIN_VER,true); 58 wp_localize_script("transposh","t_jp",array( 59 'post_url' => $this->transposh->post_url, 60 'post' => $_GET['post'], 61 'msnkey'=>$this->transposh->options->get_msn_key(), 62 'msn_langs' => json_encode($GLOBALS['bing_languages']), 63 'google_lang' => json_encode($GLOBALS['google_languages']), 64 'preferred'=> $this->transposh->options->get_preferred_translator()/*, 65 'plugin_url' => $this->transposh_plugin_url, 66 'edit' => ($this->edit_mode? '1' : ''), 67 //'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''), 68 'lang' => $this->target_language, 69 // those two options show if the script can support said engines 70 'prefix' => SPAN_PREFIX, 71 72 'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '')*/ 73 // 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};' 74 )); 58 75 wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0'); 59 76 wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',true); 77 /* if ($this->transposh->options->get_enable_msn_translate() && $this->transposh->options->get_msn_key()) { 78 wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->transposh->options->get_msn_key(),array(),'1',true); 79 }*/ 60 80 } 61 81 } … … 75 95 // TODO - grab phrases from rss excerpt 76 96 //$output = get_the_excerpt(); 77 // echo apply_filters('the_excerpt_rss', $output); 78 97 // echo apply_filters('the_excerpt_rss', $output); 98 //TODO - get comments text 99 79 100 $parser = new parser(); 80 101 $phrases = $parser->get_phrases_list($content); … … 106 127 } 107 128 129 // add the title 130 // if ($json['length']) 131 $json['posttitle'] = $title; 132 108 133 // the header helps with debugging 109 134 header("Content-type: text/javascript");
Note: See TracChangeset
for help on using the changeset viewer.
