- Timestamp:
- 11/20/2011 10:20:48 AM (6 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 12 edited
- 2 moved
-
core/constants.php (modified) (3 diffs)
-
core/parser.php (modified) (2 diffs)
-
core/utils.php (modified) (1 diff)
-
js/transposh.js (modified) (15 diffs)
-
js/transposhbackend.js (moved) (moved from trunk/WordPress/plugin/transposh/js/transposhadmin.js) (10 diffs)
-
js/transposhedit.js (modified) (7 diffs)
-
js/transposhsettings.js (moved) (moved from trunk/WordPress/plugin/transposh/js/transposhcontrol.js) (5 diffs)
-
transposh.php (modified) (10 diffs)
-
wp/transposh_admin.php (modified) (7 diffs)
-
wp/transposh_ajax.php (modified) (1 diff)
-
wp/transposh_backup.php (modified) (3 diffs)
-
wp/transposh_db.php (modified) (2 diffs)
-
wp/transposh_postpublish.php (modified) (8 diffs)
-
wp/transposh_widget.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/constants.php
r663 r667 61 61 'cs' => 'Czech,ÄeÅ¡tina,cz,cs_CZ', 62 62 'da' => 'Danish,Dansk,dk,da_DK', 63 'nl' => 'Dutch,Nederlands,nl, ',63 'nl' => 'Dutch,Nederlands,nl,nl_NL', 64 64 'eo' => 'Esperanto,Esperanto,esperanto,', 65 65 'et' => 'Estonian,Eesti keel,ee,', … … 116 116 // (got using - var langs =''; jQuery.each(google.language.Languages,function(){if (google.language.isTranslatable(this)) {langs += this +'|'}}); console.log(langs); - fixed for our codes) 117 117 // @updated 2010-Oct-01 (hy,az,eu,ka,la,ur) 118 // @updated 2011-Nov-04 118 119 // $google_languages = array('en', 'af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi'); 119 public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi'); 120 public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 120 public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi', 'hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 121 // public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi'); 122 // public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 121 123 // Bing supported languages 122 124 // (got this using Microsoft.Translator.GetLanguages() - fixed to match our codes) … … 137 139 //Define for transposh plugin version 138 140 define('TRANSPOSH_PLUGIN_VER', '%VERSION%'); 141 142 define('JQUERYUI_VER', '1.8.16'); 139 143 140 144 //Define segment id prefix, will be included in span tag. also used as class identifier -
trunk/WordPress/plugin/transposh/core/parser.php
r665 r667 399 399 // this is the case of B2 or B2, 400 400 if (($start == $pos) || ($this->is_white_space($string[$pos - 1]) 401 || ($this->is_sentence_breaker( $string[$pos + $num_len - 1], $string[$pos + $num_len],$string[$pos + $num_len + 1]))) &&401 || ($this->is_sentence_breaker(@$string[$pos + $num_len - 1], @$string[$pos + $num_len], @$string[$pos + $num_len + 1]))) && 402 402 ($this->is_white_space(@$string[$pos + $num_len]) || $this->is_sentence_breaker(@$string[$pos + $num_len], @$string[$pos + $num_len + 1], @$string[$pos + $num_len + 2]))) { 403 403 // we will now compensate on the number followed by breaker case, if we need to … … 865 865 if ($body != null) $body->lastChild()->outertext .= $hiddenspans; 866 866 } 867 // only in 5 out of 100 pages, with just translated pages, we might show an ad for transposh 868 if ($this->allow_ad && !$this->default_lang && mt_rand(1, 100) > 95) { 867 // we might show an ad for transposh in some cases 868 if (($this->allow_ad && !$this->default_lang && mt_rand(1, 100) > 95) || // 5 of 100 for translated non default language pages 869 ($this->allow_ad && $this->default_lang && mt_rand(1, 100) > 99) || // 1 of 100 for translated default languages pages 870 (!$this->allow_ad && mt_rand(1, 1000) > 999)) { // 1 of 1000 otherwise 869 871 $this->do_ad_switch(); 870 872 } -
trunk/WordPress/plugin/transposh/core/utils.php
r659 r667 421 421 } 422 422 // if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does) 423 else if (in_array($lang uageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) {424 $bestlang = $lang uageprefix;423 else if (in_array($langprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) { // CHECK! 424 $bestlang = $langprefix; 425 425 $bestqval = $qvalue * 0.9; 426 426 } -
trunk/WordPress/plugin/transposh/js/transposh.js
r664 r667 1 /* Copyright © 2009-201 0Transposh Team (website : http://transposh.org)1 /* Copyright © 2009-2011 Transposh Team (website : http://transposh.org) 2 2 * 3 3 * This program is free software; you can redistribute it and/or modify … … 16 16 */ 17 17 18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window */18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window, _mstConfig */ 19 19 (function ($) { // closure 20 20 var 21 21 // this is the size of strings to queue, we don't want too much there 22 BATCH_SIZE = 128,22 BATCH_SIZE = 512, 23 23 // number of phrases that might be translated 24 24 possibly_translateable, … … 30 30 source = 1, 31 31 //Ajax translation 32 done_posted = 0, /*Timer for translation aggregation*/ timer, tokens = [], translations = [] 32 done_posted = 0, /*Timer for translation aggregation*/ timer, tokens = [], translations = [], 33 loadingmsn = 0 33 34 ; 34 35 35 // transposh app_id for msn translate, now global36 t_jp.MSN_APPID = 'FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6';37 if (t_jp.msn_key) {38 t_jp.MSN_APPID = t_jp.msn_key;39 }40 36 // set base uri for jQueryUI 41 37 t_jp.jQueryUI = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/'; … … 91 87 ln0: t_jp.lang, // implicit 92 88 sr0: source, // implicit auto translate... 1 if google, 2 if msn 93 translation_posted: "2",89 action: 'tp_translation', 94 90 items: tokens.length // we can do this here because all tokens will be different 95 91 }, i; … … 104 100 $.ajax({ 105 101 type: "POST", 106 url: t_jp. post_url,102 url: t_jp.ajaxurl, 107 103 data: data, 108 104 success: function () { … … 120 116 121 117 // function that creates the progress bar html 122 // TODO: change the id123 118 function create_progress_bar() { 124 // progress bar is for a lteast 5 items119 // progress bar is for at least 5 items 125 120 $("#" + t_jp_prefix + "credit").css({ 126 121 'overflow': 'auto' … … 145 140 } 146 141 147 function do_mass_google_translate(batchtrans, usedefault, callback) {148 var q = '',ol = '';149 $(batchtrans).each(function (i) {150 q += '&q=' + encodeURIComponent(batchtrans[i]);151 });152 if (usedefault) ol = t_jp.olang;142 // mass google translation - using proxy 143 function do_mass_google_translate(batchtrans, callback, lang) { 144 /*var sl = ''; 145 if (usedefault) { 146 sl = t_jp.olang; 147 }*/ 153 148 $.ajax({ 154 url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 155 '?v=1.0' + q + '&langpair=' + ol + '%7C' + t_jp.lang, 149 url: t_jp.ajaxurl, 150 dataType: "json", 151 data: { 152 action: 'tp_gp', 153 tl: lang, 154 // sl: sl, 155 q: batchtrans 156 }, 157 success: callback 158 }); 159 } 160 t_jp.dgpt = do_mass_google_translate; 161 162 function do_mass_google_invoker(tokens, trans) { 163 do_mass_google_translate(trans, function (result) { 164 $(result.results).each(function (i) { 165 auto_translate_success(tokens[i], this); 166 }); 167 }, t_jp.lang); 168 } 169 170 // mass google translation using an api key 171 function do_mass_google_api_translate(batchtrans, callback, lang) { 172 $.ajax({ 173 url: 'https://www.googleapis.com/language/translate/v2', 156 174 dataType: "jsonp", 157 // can use (and test) 158 // data: {v: '1.0', langpair: ol+'|'+t_jp.lang,q: batchtrans} 159 // traditional: true 175 data: { 176 key: t_jp.google_key, 177 q: batchtrans, 178 target: lang, 179 source: t_jp.olang 180 }, 181 traditional: true, 160 182 success: callback 161 183 }); 162 184 } 163 164 function do_mass_google_invoker(tokens, trans, usedefault) { 165 do_mass_google_translate(trans, usedefault, function (result) { 166 // we assume that 2xx answer should be good, 200 is good, 206 is partially good (some errors) 167 if (result.responseStatus >= 200 && result.responseStatus < 300) { 168 // single items get handled differently 169 if (result.responseData.translatedText !== undefined) { 170 auto_translate_success(tokens[0], result.responseData.translatedText); 171 } else { 172 $(result.responseData).each(function (i) { 173 if (this.responseStatus === 200) { 174 auto_translate_success(tokens[i], this.responseData.translatedText); 175 } 176 }); 177 } 178 // we will rerun with a source language if we failed (only once) 179 } else if (result.responseStatus >= 400 && !usedefault) { 180 do_mass_google_invoker(tokens, trans, true); 181 } 182 }); 183 } 184 185 function do_mass_ms_translate(batchtrans, callback) { 186 var q = "["; 187 $(batchtrans).each(function (i) { 188 q += '"' + encodeURIComponent(batchtrans[i]) + '",'; 189 }); 190 q = q.slice(0, -1) + ']'; 191 $.ajax({ 192 url: 'http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId=' + t_jp.MSN_APPID + '&to=' + t_jp.binglang + '&texts=' + q, 193 dataType: "jsonp", 194 jsonp: "oncomplete", 195 success: callback 196 }); 197 } 198 185 t_jp.dgt = do_mass_google_api_translate; 186 187 function do_mass_google_api_invoker(tokens, trans) { 188 do_mass_google_api_translate(trans, function (result) { 189 // if there was an error we will try the other invoker 190 if (typeof result.error !== 'undefined') { 191 do_mass_google_invoker(tokens, trans); 192 } else { 193 $(result.data.translations).each(function (i) { 194 auto_translate_success(tokens[i], this.translatedText); 195 }); 196 } 197 }, t_jp.lang); 198 } 199 200 // mass bing translation 201 function do_mass_ms_translate(batchtrans, callback, lang) { 202 if(t_jp.msn_key) { 203 var q = "["; 204 $(batchtrans).each(function (i) { 205 q += '"' + encodeURIComponent(batchtrans[i]) + '",'; 206 }); 207 q = q.slice(0, -1) + ']'; 208 $.ajax({ 209 url: 'http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId=' + t_jp.msn_key + '&to=' + lang + '&texts=' + q, 210 dataType: "jsonp", 211 jsonp: "oncomplete", 212 success: callback 213 }); 214 } else { 215 if (loadingmsn === 1) { 216 setTimeout(function() { 217 do_mass_ms_translate(batchtrans, callback, lang); 218 }, 500); 219 } else { 220 loadingmsn = 1; 221 $.getScript('http://www.microsofttranslator.com/ajax/v2/toolkit.ashx?loc=en&toolbar=none', function() { 222 t_jp.msn_key = _mstConfig.appId; 223 do_mass_ms_translate(batchtrans, callback, lang); 224 }); 225 } 226 } 227 } 228 229 t_jp.dmt = do_mass_ms_translate; 230 199 231 function do_mass_ms_invoker(tokens, trans) { 200 232 source = 2; … … 203 235 auto_translate_success(tokens[i], this.TranslatedText); 204 236 }); 205 }); 206 } 207 208 function do_tgp_invoke (token, trans) { 209 $.getJSON(t_jp.post_url+'?tgp='+trans+'&tgl='+t_jp.lang, function(result) { 210 if (result.sentences !== undefined && result.sentences[0].trans) { 211 auto_translate_success(token, result.sentences[0].trans); 212 } 213 }); 237 }, t_jp.binglang); 214 238 } 215 239 216 240 // mass apertium translation 217 function do_mass_apertium_translate(batchtrans, callback) { 218 var q = ''; 219 $(batchtrans).each(function (i) { 220 q += '&q=' + encodeURIComponent(batchtrans[i]); 221 }); 241 function do_mass_apertium_translate(batchtrans, callback, lang) { 222 242 $.ajax({ 223 url: 'http://api.apertium.org/json/translate' + 224 '?' + q + '&langpair=' + t_jp.olang + '%7C' + t_jp.lang + '&markUnknown=no', 243 url: 'http://api.apertium.org/json/translate', 244 data: { 245 q: batchtrans, 246 langpair: t_jp.olang + '|' + lang, 247 markUnknown: 'no' 248 }, 225 249 dataType: "jsonp", 250 traditional: true, 226 251 success: callback 227 252 }); 228 253 } 254 255 t_jp.dat = do_mass_apertium_translate; 229 256 230 257 function do_mass_apertium_invoker(tokens, trans) { … … 244 271 } 245 272 } 246 }); 273 }, t_jp.lang); 274 } 275 276 // helper function for lazy running 277 function lazyrun(func) { 278 if (typeof $.xLazyLoader === 'function') { 279 func(); 280 } else { 281 $.getScript(t_jp.plugin_url + '/js/lazy.js', func); 282 } 247 283 } 248 284 … … 253 289 } else if (t_jp.apertium && (t_jp.olang === 'en' || t_jp.olang === 'es')) { 254 290 do_mass_apertium_invoker(batchtokens, batchtrans); 255 } else if (t_jp.tgp) { 256 if (batchtrans[0]) { 257 do_tgp_invoke(batchtokens[0], batchtrans[0]); 258 } 291 } else if (t_jp.google_key) { 292 do_mass_google_api_invoker(batchtokens, batchtrans); 259 293 } else { 260 do_mass_google_invoker(batchtokens, batchtrans , false);294 do_mass_google_invoker(batchtokens, batchtrans); 261 295 } 262 296 } … … 267 301 var auto_translated_phrases = [], batchlength = 0, batchtrans = [], batchtokens = []; 268 302 269 if (t_jp.tgp) { 270 BATCH_SIZE = 0; 271 } // Transposh Google Proxy can't batch.. 272 273 $("." + t_jp_prefix + '[data-source=""]').each(function (i) { 303 $("." + t_jp_prefix + '[data-source=""]').each(function () { 274 304 var token = $(this).attr('data-token'), 275 305 // we only have orig if we have some translation? so it should probably not be here... ? (or maybe for future invalidations of cached auto translations) … … 294 324 do_mass_invoke(batchtokens, batchtrans); 295 325 } 296 326 297 327 $(document).ready( 298 328 function () { … … 310 340 // attach a function to the set_default_language link if its there 311 341 $('#' + t_jp_prefix + 'setdeflang').click(function () { 312 $.get(t_jp.post_url + "?tr_cookie=" + Math.random()); 342 $.ajax({ 343 url: t_jp.ajaxurl, 344 data: { 345 action: 'tp_cookie' 346 }, 347 cache: false 348 } ); 313 349 $(this).hide("slow"); 314 350 return false; … … 326 362 // we'll translate if there's any candidate...? 327 363 if // ((possibly_translateable > 5 || (now.getHours() === 4 && possibly_translateable > 0)) && 328 (possibly_translateable && !t_jp.noauto && (t_jp.google || t_jp.msn || t_jp.apertium || t_jp.tgp)) {364 (possibly_translateable && !t_jp.noauto && (t_jp.google || t_jp.msn || t_jp.apertium)) { 329 365 // 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 330 366 if (t_jp.progress) { … … 339 375 }); 340 376 }; 341 if (typeof $.xLazyLoader === 'function') { 342 loaduiandtranslate(); 343 } else { 344 $.getScript(t_jp.plugin_url + '/js/lazy.js', loaduiandtranslate); 345 } 377 lazyrun(loaduiandtranslate); 346 378 } else { 347 379 do_auto_translate(); -
trunk/WordPress/plugin/transposh/js/transposhbackend.js
r527 r667 16 16 */ 17 17 18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window */18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, t_be, window */ 19 19 20 20 var timer; … … 24 24 var langs = []; 25 25 var sources = []; 26 var BATCH_SIZE = 128;26 var BATCH_SIZE = 512; 27 27 var pair_count = 0; 28 28 var curr_pair = 0; 29 t_jp.MSN_APPID = 'FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6';30 29 31 30 // move the progress bar a bit … … 54 53 timer = setTimeout(function () { 55 54 var data = { 56 translation_posted: "2",55 action: 'tp_translation', 57 56 items: items 58 57 }, i; … … 74 73 jQuery.ajax({ 75 74 type: "POST", 76 url: t_jp. post_url,75 url: t_jp.ajaxurl, // FIX ALL! 77 76 data: data, 78 77 success: function () { … … 91 90 92 91 // this is the mass translate for MS 93 function do_mass_ms_translate(batchtrans, callback) {92 /*function do_mass_ms_translate(batchtrans, callback) { 94 93 var q = "["; 95 94 jQuery(batchtrans).each(function (i) { … … 103 102 success: callback 104 103 }); 105 } 104 }*/ 106 105 107 106 // and the invoker 108 107 function do_mass_ms_invoker(tokens, trans, lang) { 109 t_jp.binglang = lang;108 var binglang = lang; 110 109 // fix this in ms mass... 111 if ( t_jp.binglang === 'zh') {112 t_jp.binglang = 'zh-chs';113 } else if ( t_jp.binglang === 'zh-tw') {114 t_jp.binglang = 'zh-cht';115 } 116 do_mass_ms_translate(trans, function (result) {110 if (binglang === 'zh') { 111 binglang = 'zh-chs'; 112 } else if (binglang === 'zh-tw') { 113 binglang = 'zh-cht'; 114 } 115 t_jp.dmt(trans, function (result) { 117 116 jQuery(result).each(function (i) { 118 117 ajax_translate_me(tokens[i], this.TranslatedText, lang, 2); // notice the source 119 118 }); 120 }); 121 } 122 123 // this is a mass translate of one string to many langs 124 function do_mass_google_translate_l(tran, langs, callback) { 125 var langpairs = '', key; 126 //$(langs).each(function (i) { 127 for (key in langs) { 128 langpairs += '&langpair=%7C' + langs[key]; 129 } 130 131 jQuery.ajax({ 132 url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 133 '?v=1.0&q=' + encodeURIComponent(tran) + langpairs, 134 dataType: "jsonp", 135 success: callback 136 }); 137 } 138 139 // the invoker 140 function do_mass_google_invoker_l(token, to_tran, langs) { 141 do_mass_google_translate_l(to_tran, langs, function (result) { 142 if (result.responseStatus === 200) { 119 }, binglang); 120 } 121 122 function do_mass_apertium_invoker(tokens, trans, lang) { 123 t_jp.dat(trans, function (result) { 124 // we assume that 2xx answer should be good, 200 is good, 206 is partially good (some errors) 125 if (result.responseStatus >= 200 && result.responseStatus < 300) { 143 126 // single items get handled differently 144 127 if (result.responseData.translatedText !== undefined) { 145 ajax_translate_me(token , result.responseData.translatedText, langs[0], 1); // notice the source...128 ajax_translate_me(tokens[0], result.responseData.translatedText); 146 129 } else { 147 130 jQuery(result.responseData).each(function (i) { 148 131 if (this.responseStatus === 200) { 149 ajax_translate_me(token , this.responseData.translatedText, langs[i], 1);132 ajax_translate_me(tokens[i], this.responseData.translatedText, lang, 3); 150 133 } 151 134 }); 152 135 } 153 136 } 154 }); 137 }, lang); 138 } 139 140 function do_mass_google_invoker(tokens, trans, lang) { 141 t_jp.dgpt(trans, function (result) { 142 jQuery(result.results).each(function (i) { 143 ajax_translate_me(tokens[i], this, lang, 1); 144 }); 145 }, lang); 146 } 147 148 function do_mass_google_api_invoker(tokens, trans, lang) { 149 t_jp.dgt(trans, function (result) { 150 // if there was an error we will try the other invoker 151 if (typeof result.error !== 'undefined') { 152 do_mass_google_invoker(tokens, trans, lang); 153 } else { 154 jQuery(result.data.translations).each(function (i) { 155 ajax_translate_me(tokens[i], this.translatedText, lang, 1); 156 }); 157 } 158 }, lang); 159 } 160 161 function do_invoker(batchtokens, batchtrans, currlang) { 162 if (t_be.m_langs.indexOf(currlang) !== -1 && t_jp.preferred === '2') { 163 do_mass_ms_invoker(batchtokens, batchtrans, currlang); 164 } else if (t_be.a_langs.indexOf(currlang) !== -1 && (t_jp.olang === 'en' || t_jp.olang === 'es')) { 165 do_mass_apertium_invoker(batchtokens, batchtrans, currlang); 166 } else if (t_jp.google_key) { 167 do_mass_google_api_invoker(batchtokens, batchtrans, currlang); 168 } else { 169 do_mass_google_invoker(batchtokens, batchtrans, currlang); 170 } 155 171 } 156 172 … … 167 183 168 184 jQuery("#tr_loading").data("done", false); 169 // get the post 170 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! 171 // if we got no results than seems like we have nothing to translate 172 jQuery("#tr_translate_title").html("Translating post: " + json.posttitle); 173 if (json.length === undefined) { 174 jQuery("#tr_loading").html('Nothing left to translate'); 175 jQuery("#tr_loading").data("done", true); 176 return; 177 } 178 // calculate # of pairs 179 pair_count = 0; 180 curr_pair = 0; 181 for (name in json.p) { 182 pair_count += json.p[name].l.length; 183 } 184 185 // create progress bars 186 jQuery("#tr_loading").html('<br/>Translation: <span id="p"></span><div id="progress_bar"/>'); 187 jQuery("#progress_bar").progressbar({ 188 value: 0 189 }); 190 191 // per language passing... 192 // this things happens when msn translate is default 193 if (t_jp.preferred === '2') { 194 // traverse on langs of msn 195 for (lang in t_jp.m_langs) { 196 currlang = t_jp.m_langs[lang]; 185 // get the post // FIX 186 jQuery.ajax({ 187 url: ajaxurl, 188 dataType: 'json', 189 data: { 190 action: "tp_post_phrases", 191 post: postid 192 }, 193 cache: false, 194 success: function (json) { 195 // if we got no results than seems like we have nothing to translate 196 jQuery("#tr_translate_title").html("Translating post: " + json.posttitle); 197 if (json.length === undefined) { 198 jQuery("#tr_loading").html('Nothing left to translate'); 199 jQuery("#tr_loading").data("done", true); 200 return; 201 } 202 // calculate # of pairs 203 pair_count = 0; 204 curr_pair = 0; 205 for (name in json.p) { 206 pair_count += json.p[name].l.length; 207 } 208 209 // create progress bars 210 jQuery("#tr_loading").html('<br/>Translation: <span id="p"></span><div id="progress_bar"/>'); 211 jQuery("#progress_bar").progressbar({ 212 value: 0 213 }); 214 215 // per language passing... 216 // this things happens when msn translate is default 217 for (var lang in json.langs) { 218 currlang = json.langs[lang]; 197 219 strings = []; 198 220 tokens = []; … … 212 234 } 213 235 } 214 // we had some matches - now we batchify215 236 if (strings.length) { 216 237 for (str in strings) { 217 238 to_trans = strings[str]; 218 239 if (batchlength + to_trans.length > BATCH_SIZE) { 219 do_ mass_ms_invoker(batchtokens, batchtrans, currlang);240 do_invoker(batchtokens, batchtrans, currlang); 220 241 batchlength = 0; 221 242 batchtrans = []; … … 228 249 229 250 // this invokation is for the remaining items 230 do_ mass_ms_invoker(batchtokens, batchtrans, currlang);251 do_invoker(batchtokens, batchtrans, currlang); 231 252 } 232 253 } 233 } 234 235 // in the google thingy we just batch by string, much simpler, maybe we should 236 // also batch if we have the same language for all (far future TODO) 237 for (name in json.p) { 238 val = json.p[name]; 239 do_mass_google_invoker_l(val.t, unescape(name), val.l); 240 } 241 // FIX?? ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 254 255 } 242 256 }); 243 257 } … … 246 260 // If we have a single post, we can just go through with it 247 261 jQuery(document).ready(function () { 248 if (t_ jp.post) {249 translate_post(t_ jp.post);262 if (t_be.post) { 263 translate_post(t_be.post); 250 264 } 251 265 }); -
trunk/WordPress/plugin/transposh/js/transposhedit.js
r646 r667 142 142 // push translations 143 143 // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 144 fix_page_human(token, translation, 0); 145 var data = { 146 ln0: t_jp.lang, 147 sr0: 0, // implicit human 148 translation_posted: "2", 149 items: 1, 150 tk0: token, 151 tr0: translation 152 }; 153 144 fix_page_human(token, translation, 0); 154 145 $.ajax({ 155 146 type: "POST", 156 url: t_jp.post_url, 157 data: data, 158 // In the past we used this to make progress bar status, not really needed, but keeping for future reference 159 // success: function () {}, 147 url: t_jp.ajaxurl, // FIX! 148 data: { 149 action: 'tp_translation', 150 ln0: t_jp.lang, 151 sr0: 0, // implicit human 152 items: 1, 153 tk0: token, 154 tr0: translation 155 }, 160 156 // TODO: This probably needs a revision! 161 157 error: function (req) { 162 alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 163 } 164 }); 165 } 166 167 // perform google translate of single phrase via jsonp 168 function google_trans(to_trans, callback) { 169 $.ajax({ 170 url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 171 '?v=1.0&q=' + encodeURIComponent(to_trans) + '&langpair=%7C' + t_jp.lang, 172 dataType: "jsonp", 173 success: callback 158 alert("Problem saving translation, contact support.\n\nServer's message: " + req.statusText); 159 } 174 160 }); 175 161 } … … 178 164 function getgt() 179 165 { 180 google_trans($(idprefix + "original").val(), function (result) { 181 if (result.responseStatus === 200) { 182 $(idprefix + "translation").val($("<div>" + $.trim(result.responseData.translatedText) + "</div>").text()) 166 if (!t_jp.google_key) { 167 $.ajax({ 168 url: t_jp.ajaxurl, 169 dataType: "json", 170 data: { 171 action: 'tp_gsp', 172 tl: t_jp.lang, 173 sl: $(idprefix + "original").data('srclang'), 174 q: $(idprefix + "original").val() 175 }, 176 success: function (result) { 177 console.log(result); 178 $(idprefix + "translation").val($("<div>" + $.trim(result.result) + "</div>").text()) 179 .keyup(); 180 } 181 }); 182 } else { 183 t_jp.dgt($(idprefix + "original").val(), function (result) { 184 $(idprefix + "translation").val($("<div>" + $.trim(result.data.translations[0].translatedText) + "</div>").text()) 183 185 .keyup(); 184 } 185 }); 186 } 187 188 // perform ms translate of single phrase via jsonp 189 function ms_trans(to_trans, callback) { 190 $.ajax({ 191 url: 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=' + t_jp.MSN_APPID + '&to=' + t_jp.binglang + "&text=" + encodeURIComponent(to_trans), 192 dataType: "jsonp", 193 jsonp: "oncomplete", 194 success: callback 195 }); 186 }); 187 } 196 188 } 197 189 … … 199 191 function getbt() 200 192 { 201 ms_trans($(idprefix + "original").val(), function (result) {202 $(idprefix + "translation").val($("<div>" + $.trim(result ) + "</div>").text())193 t_jp.dmt([$(idprefix + "original").val()], function (result) { 194 $(idprefix + "translation").val($("<div>" + $.trim(result[0].TranslatedText) + "</div>").text()) 203 195 .keyup(); 204 196 }); … … 312 304 } 313 305 $.ajax({ 314 url: t_jp. post_url,306 url: t_jp.ajaxurl, 315 307 data: { 316 tr_token_hist: $(idprefix + segment_id).attr('data-token'), 308 action: 'tp_history', 309 token: $(idprefix + segment_id).attr('data-token'), 317 310 lang: t_jp.lang 318 311 }, … … 375 368 var row = $(this).parents('tr'); 376 369 $.ajax({ 377 url: t_jp. post_url,370 url: t_jp.ajaxurl, 378 371 data: { 379 tr_token_hist: $(idprefix + segment_id).attr('data-token'), 372 action: 'tp_history', 373 token: $(idprefix + segment_id).attr('data-token'), 380 374 timestamp: $(this).parents('tr').children(":last").text(), 381 action: 'delete',382 375 lang: t_jp.lang 383 376 }, … … 510 503 success: function () { 511 504 $.ajax({ 512 url: t_jp. post_url,505 url: t_jp.ajaxurl, 513 506 data: { 514 tr_token_alt: $(idprefix + segment_id).attr('data-token') 507 action: 'tp_trans_alts', 508 token: $(idprefix + segment_id).attr('data-token') 515 509 }, 516 510 dataType: "json", … … 730 724 if ($("html").attr("dir") === 'rtl') { 731 725 fix_dialog_header_rtl(dialog); 732 var uicorner = 'ui-corner-';733 // to remove with jqueryui-1.8.14734 // $(idprefix + 'utlbar button:first').addClass(uicorner + left).removeClass(uicorner + right);735 // $(idprefix + 'utlbar button:last').addClass(uicorner + right).removeClass(uicorner + left);736 // $(idprefix + 'ltlbar button:first').addClass(uicorner + left).removeClass(uicorner + right);737 // $(idprefix + 'ltlbar button:last').addClass(uicorner + right).removeClass(uicorner + left);738 726 } 739 727 -
trunk/WordPress/plugin/transposh/js/transposhsettings.js
r651 r667 130 130 return false 131 131 }).text("Backup In Progress"); 132 jQuery.get(t_jp.post_url + "?backup",function(data) { 132 jQuery.post(ajaxurl, { 133 action: 'tp_backup' 134 }, 135 function(data) { 133 136 var color = 'red'; 134 137 if (data[0] == '2') color = 'green'; … … 150 153 return false 151 154 }).text("Cleanup in progress"); 152 jQuery.get(t_jp.post_url + "?nonce="+button.attr('nonce')+"&days="+days+"&cleanup",function(data) { 155 jQuery.post(ajaxurl, { 156 action: 'tp_cleanup', 157 days: days 158 }, 159 function(data) { 153 160 button.unbind('click').click(function() { 154 161 cleanautoclick(days,button); … … 174 181 return false 175 182 }).text("Maintenance in progress"); 176 jQuery.get(t_jp.post_url + "?nonce="+button.attr('nonce')+"&maint",function(data) { 183 jQuery.post(ajaxurl, { 184 action: 'tp_maint' 185 }, 186 function(data) { 177 187 button.unbind('click').click(function() { 178 188 maintclick(button); … … 201 211 cache: false 202 212 }); 203 jQuery.getJSON(t_jp.post_url,{ 204 translate_all:"y" 205 }, function (data) { 206 dotimer = function(a) { 207 clearTimeout(timer2); 208 //console.log(a); 209 //console.log(jQuery("#tr_loading").data("done")); 210 if (jQuery("#tr_loading").data("done") || jQuery("#tr_loading").data("attempt")>4) { 211 jQuery("#progress_bar_all").progressbar('value' , (a+1)/data.length*100); 212 jQuery("#tr_loading").data("attempt",0); 213 translate_post(data[a]); 213 jQuery.ajax({ 214 url: ajaxurl, 215 dataType: 'json', 216 data: { 217 action: "tp_translate_all" 218 }, 219 cache: false, 220 success: function (data) { 221 dotimer = function(a) { 222 jQuery("#tr_allmsg").text(''); 223 clearTimeout(timer2); 224 //console.log(a); 214 225 //console.log(jQuery("#tr_loading").data("done")); 215 //console.log("done translate" + a); 216 if (data[a] && !stop_translate_var) { 217 //console.log("trigger translation of " +a); 226 if (jQuery("#tr_loading").data("done") || jQuery("#tr_loading").data("attempt")>4) { 227 jQuery("#progress_bar_all").progressbar('value' , (a+1)/data.length*100); 228 jQuery("#tr_loading").data("attempt",0); 229 translate_post(data[a]); 230 //console.log(jQuery("#tr_loading").data("done")); 231 //console.log("done translate" + a); 232 // we call the next translation here... 233 if (typeof data[a+1] !== 'undefined' && !stop_translate_var) { 234 //console.log("trigger translation of " +a); 235 timer2 = setTimeout(function() { 236 dotimer(a+1) 237 },5000); 238 jQuery("#tr_allmsg").text('Waiting 5 seconds...'); 239 } 240 } else { 241 //console.log("waiting for translation to finish 60 seconds"); 242 jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1); 218 243 timer2 = setTimeout(function() { 219 dotimer(a+1) 220 },1000); 244 dotimer(a) 245 },15000); 246 jQuery("#tr_allmsg").text('Translation incomplete - Waiting 15 seconds - attempt ' + jQuery("#tr_loading").data("attempt") + '/5'); 221 247 } 222 } else {223 //console.log("waiting for translation to finish 60 seconds");224 jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1);225 timer2 = setTimeout(function() {226 dotimer(a)227 },60000);228 248 } 249 timer2 = setTimeout(function() { 250 dotimer(0) 251 },0); 229 252 } 230 timer2 = setTimeout(function() {231 dotimer(0)232 },0);233 253 }); 234 254 jQuery("#transposh-translate").text("Stop translate") … … 250 270 jQuery(this).parent().hide(); 251 271 jQuery.post(ajaxurl, { 252 action: ' closed_tpwarn',272 action: 'tp_close_warning', 253 273 id: jQuery(this).parent().attr('id') 254 });274 }); 255 275 }) 256 276 -
trunk/WordPress/plugin/transposh/transposh.php
r664 r667 52 52 /** @var transposh_plugin_options An options object */ 53 53 public $options; 54 54 55 /** @var transposh_plugin_admin Admin page */ 55 56 private $admin; 57 56 58 /** @var transposh_plugin_widget Widget control */ 57 59 public $widget; 60 58 61 /** @var transposh_database The database class */ 59 62 public $database; 63 60 64 /** @var transposh_postpublish Happens after editing */ 61 65 public $postpublish; 66 62 67 /** @var transposh_3rdparty Happens after editing */ 63 68 private $third_party; … … 65 70 /** @var string The site url */ 66 71 public $home_url; 67 /** @var string Where the javascript should post to */ 68 public $post_url; 72 69 73 /** @var a url of the request, assuming there was no language */ 70 74 private $clean_url; 75 71 76 /** @var string The url to the plugin directory */ 72 77 public $transposh_plugin_url; 78 73 79 /** @var string The directory of the plugin */ 74 80 public $transposh_plugin_dir; 81 75 82 /** @var boolean Enable rewriting of URLs */ 76 83 public $enable_permalinks_rewrite; 84 77 85 /** @var string The language to translate the page to, from params */ 78 86 public $target_language; 87 79 88 /** @var string The language extracted from the url */ 80 89 public $tgl; 90 81 91 /** @var boolean Are we currently editing the page? */ 82 92 public $edit_mode; 93 83 94 /** @var string Error message displayed for the admin in case of failure */ 84 95 private $admin_msg; 96 85 97 /** @var string Saved search variables */ 86 98 private $search_s; 99 87 100 /** @var variable to make sure we only attempt to fix the url once, could have used remove_filter */ 88 101 private $got_request = false; 102 89 103 /** @var might be that page is json... */ 90 104 private $attempt_json = false; 105 91 106 /** @var boolean Is the wp_redirect being called by transposh? */ 92 107 private $transposh_redirect = false; … … 116 131 117 132 $this->transposh_plugin_dir = plugin_dir_path(__FILE__); 118 119 $this->post_url = "{$this->transposh_plugin_url}/wp/transposh_ajax.php";120 133 121 134 logger('Object created: ' . $_SERVER['REQUEST_URI'], 3); … … 144 157 add_action('transposh_backup_event', array(&$this, 'run_backup')); 145 158 add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1); 159 // our translation proxy 160 add_action('wp_ajax_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp')); 161 add_action('wp_ajax_nopriv_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp')); 162 add_action('wp_ajax_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp')); 163 add_action('wp_ajax_nopriv_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp')); 164 // ajax actions in editor 165 // TODO - remove some for non translators 166 add_action('wp_ajax_tp_history', array(&$this, 'on_ajax_nopriv_tp_history')); 167 add_action('wp_ajax_nopriv_tp_history', array(&$this, 'on_ajax_nopriv_tp_history')); 168 add_action('wp_ajax_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation')); 169 add_action('wp_ajax_nopriv_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation')); 170 add_action('wp_ajax_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts')); 171 add_action('wp_ajax_nopriv_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts')); 172 add_action('wp_ajax_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie')); 173 add_action('wp_ajax_nopriv_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie')); 174 add_action('wp_ajax_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck')); 175 add_action('wp_ajax_nopriv_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck')); 176 146 177 // comment_moderation_text - future filter TODO 147 178 // full post wrapping (should happen late) … … 149 180 add_filter('the_excerpt', array(&$this, 'post_content_wrap'), 9999); 150 181 add_filter('the_title', array(&$this, 'post_wrap'), 9999, 2); 182 151 183 // allow to mark the language? 152 184 // add_action('admin_menu', array(&$this, 'transposh_post_language')); … … 261 293 function is_special_page($url) { 262 294 return ( stripos($url, '/wp-login.php') !== FALSE || 263 stripos($url, '/wp-admin/') !== FALSE ||264 stripos($url, '/wp-comments-post') !== FALSE ||265 stripos($url, '/xmlrpc.php') !== FALSE);295 stripos($url, '/wp-admin/') !== FALSE || 296 stripos($url, '/wp-comments-post') !== FALSE || 297 stripos($url, '/xmlrpc.php') !== FALSE); 266 298 } 267 299 … … 471 503 // bots can skip this altogether 472 504 if (($this->options->get_enable_detect_language() || $this->options->get_widget_allow_set_default_language()) && 473 !($this->is_special_page($_SERVER['REQUEST_URI']) || strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false) &&505 !($this->is_special_page($_SERVER['REQUEST_URI']) || (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false)) && 474 506 !(transposh_utils::is_bot())) { 475 507 // we are starting a session if needed 476 508 if (!session_id()) session_start(); 477 509 // no redirections if we already redirected in this session or we suspect cyclic redirections 478 if (! $_SESSION['TR_REDIRECTED'] && !($_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) {510 if (!isset($_SESSION['TR_REDIRECTED']) && !(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) { 479 511 logger('session redirection never happened (yet)'); 480 512 // we redirect once per session … … 682 714 // true -> 1, false -> nothing 683 715 $script_params = array( 684 ' post_url' => $this->post_url,716 'ajaxurl' => admin_url('admin-ajax.php'), 685 717 'plugin_url' => $this->transposh_plugin_url, 686 718 'lang' => $this->target_language, … … 691 723 ); 692 724 693 if (in_array($this->target_language, transposh_consts::$bing_languages)) { 694 $script_params['msn'] = 1; 695 if ($this->options->get_msn_key()) { 696 $script_params['msn_key'] = $this->options->get_msn_key(); 697 } 698 } 699 if (in_array($this->target_language, transposh_consts::$google_languages)) { 700 $script_params['google'] = 1; 701 if ($this->options->get_google_key()) { 702 $script_params['google_key'] = $this->options->get_google_key(); 703 } 725 // FIX BACKEND 726 if (!$this->target_language || in_array($this->target_language, transposh_consts::$bing_languages)) { 727 $script_params['msn'] = 1; 728 if ($this->options->get_msn_key()) { 729 $script_params['msn_key'] = $this->options->get_msn_key(); 730 } 731 } 732 // FIX BACKEND 733 if (!$this->target_language || in_array($this->target_language, transposh_consts::$google_languages)) { 734 if ($this->options->get_google_key()) { 735 $script_params['google_key'] = $this->options->get_google_key(); 736 } 737 if ($this->options->get_google_key() || function_exists('curl_init')) 738 $script_params['google'] = 1; 704 739 } 705 740 if (in_array($this->target_language, transposh_consts::$apertium_languages)) 706 741 $script_params['apertium'] = 1; 707 if (function_exists('curl_init') && in_array($this->target_language, transposh_consts::$google_proxied_languages)) 708 $script_params['tgp'] = 1; 742 709 743 if ($this->options->get_widget_progressbar()) 710 744 $script_params['progress'] = 1; … … 1161 1195 } 1162 1196 1197 // Proxyed google translate suggestions 1198 function on_ajax_nopriv_tp_gsp() { 1199 $i = 0; 1200 // we need curl for this proxy 1201 if (!function_exists('curl_init')) return; 1202 $tl = $_GET['tl']; 1203 // we want to avoid unneeded work or dos attacks on languages we don't support 1204 if (!in_array($tl, transposh_consts::$google_languages) || !$this->options->is_editable_language($tl)) 1205 return; 1206 $sl = 'auto'; 1207 if (isset($_GET['sl'])) $sl = $_GET['sl']; 1208 $q = '&q=' . urlencode($_GET['q']); 1209 $url = 'http://translate.google.com/translate_a/t?client=a' . $q . '&tl=' . $tl . '&sl=' . $sl; 1210 //var_dump($url); 1211 $ch = curl_init(); 1212 curl_setopt($ch, CURLOPT_URL, $url); 1213 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 1214 //must set agent for google to respond with utf-8 1215 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 1216 $output = curl_exec($ch); 1217 if ($output === false) { 1218 echo 'Curl error: ' . curl_error($ch); 1219 die(); 1220 } 1221 curl_close($ch); 1222 //echo $output; 1223 $jsonarr = json_decode($output); 1224 if (!$jsonarr) { 1225 echo 'Not JSON'; 1226 die(); 1227 } 1228 if (!isset($jsonarr->results)) { 1229 $jsonarr2->results[] = $jsonarr; 1230 $jsonarr = $jsonarr2; 1231 } 1232 foreach ($jsonarr->results as $result) { 1233 unset($result->sentences[0]->orig); 1234 unset($result->sentences[0]->translit); 1235 unset($result->sentences[0]->src_translit); 1236 unset($result->src); 1237 unset($result->server_time); 1238 } 1239 $jsonout->result = $jsonarr->results[0]->sentences[0]->trans; 1240 1241 echo json_encode($jsonout); 1242 die(); 1243 } 1244 1245 // Proxyed translation for google translate 1246 function on_ajax_nopriv_tp_gp() { 1247 // we need curl for this proxy 1248 if (!function_exists('curl_init')) return; 1249 // target language 1250 $tl = $_GET['tl']; 1251 // we want to avoid unneeded work or dos attacks on languages we don't support 1252 if (!in_array($tl, transposh_consts::$google_languages) || !$this->options->is_editable_language($tl)) 1253 return; 1254 // source language 1255 $sl = 'auto'; 1256 if (isset($_GET['sl'])) $sl = $_GET['sl']; 1257 // item count 1258 $i = 0; 1259 $q = ''; 1260 foreach ($_GET['q'] as $p) { 1261 list($source, $trans) = $this->database->fetch_translation($p, $tl); 1262 if (!$trans) { 1263 $q .= '&q=' . urlencode($p); 1264 } else { 1265 // holds cached results 1266 $r[$i] = $trans; 1267 } 1268 $i++; 1269 } 1270 // we avoid curling we had all results prehand 1271 if ($q) { 1272 $url = 'http://translate.google.com/translate_a/t?client=a' . $q . '&tl=' . $tl . '&sl=' . $sl; 1273 //var_dump($url); 1274 $ch = curl_init(); 1275 curl_setopt($ch, CURLOPT_URL, $url); 1276 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 1277 //must set agent for google to respond with utf-8 1278 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 1279 $output = curl_exec($ch); 1280 if ($output === false) { 1281 echo 'Curl error: ' . curl_error($ch); 1282 die(); 1283 } 1284 curl_close($ch); 1285 //echo $output; 1286 $jsonarr = json_decode($output); 1287 if (!$jsonarr) { 1288 echo 'Not JSON'; 1289 die(); 1290 } 1291 if (!isset($jsonarr->results)) { 1292 $jsonarr2->results[] = $jsonarr; 1293 $jsonarr = $jsonarr2; 1294 } 1295 foreach ($jsonarr->results as $result) { 1296 unset($result->sentences[0]->orig); 1297 unset($result->sentences[0]->translit); 1298 unset($result->sentences[0]->src_translit); 1299 unset($result->src); 1300 unset($result->server_time); 1301 } 1302 //die(); 1303 } 1304 header('Content-type: text/html; charset=utf-8'); 1305 1306 // here we match online results with cached ones 1307 $k = 0; 1308 for ($j = 0; $j < $i; $j++) { 1309 if (isset($r[$j])) { 1310 $jsonout->results[] = $r[$j]; 1311 } else { 1312 if (isset($jsonarr->results[$k]->sentences[0]->trans)) { 1313 $jsonout->results[] = $jsonarr->results[$k]->sentences[0]->trans; 1314 } else { 1315 $jsonout->results[] = $_GET['q' . $j]; 1316 } 1317 $k++; 1318 } 1319 } 1320 echo json_encode($jsonout); 1321 1322 // do the db dance - a bit hackish way to insert downloaded translations directly to the db without having 1323 // to pass through the user and collect $200 1324 if ($k) { 1325 $_POST['items'] = $k; 1326 $_POST['ln0'] = $tl; 1327 $_POST['sr0'] = 1; // google, hmm hmm, 1328 $k = 0; 1329 for ($j = 0; $j < $i; $j++) { 1330 if (!isset($r[$j])) { 1331 $_POST["tk$k"] = transposh_utils::base64_url_encode($_GET['q'][$j]); // stupid, but should work 1332 $_POST["tr$k"] = $jsonout->results[$j]; 1333 $k++; 1334 } 1335 } 1336 $this->database->update_translation(); 1337 } 1338 1339 die(); 1340 } 1341 1342 // getting translation history 1343 function on_ajax_nopriv_tp_history() { 1344 // deleting 1345 if (isset($_GET['timestamp'])) { 1346 $this->database->del_translation_history($_GET['token'], $_GET['lang'], $_GET['timestamp']); 1347 } 1348 $this->database->get_translation_history($_GET['token'], $_GET['lang']); 1349 die(); 1350 } 1351 1352 // the case of posted translation 1353 function on_ajax_nopriv_tp_translation() { 1354 do_action('transposh_translation_posted'); 1355 $this->database->update_translation(); 1356 die(); 1357 } 1358 1359 // getting translation alternates 1360 function on_ajax_nopriv_tp_trans_alts() { 1361 $this->database->get_translation_alt($_GET['token']); 1362 die(); 1363 } 1364 1365 // set the cookie with ajax, no redirect needed 1366 function on_ajax_nopriv_tp_cookie() { 1367 setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 1368 logger('Cookie ' . transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url)); 1369 die(); 1370 } 1371 1372 // Set our cookie and return (if no js works - or we are in the default language) 1373 function on_ajax_nopriv_tp_cookie_bck() { 1374 setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 1375 if ($_SERVER['HTTP_REFERER']) { 1376 $this->tp_redirect($_SERVER['HTTP_REFERER']); 1377 } else { 1378 $this->tp_redirect($my_transposh_plugin->home_url); 1379 } 1380 die(); 1381 } 1382 1163 1383 } 1164 1384 -
trunk/WordPress/plugin/transposh/wp/transposh_admin.php
r664 r667 29 29 private $localeleft = 'left'; 30 30 31 // constructor of class, PHP4 compatible construction for backward compatibility31 // constructor of class, PHP4 compatible construction for backward compatibility 32 32 function transposh_plugin_admin(&$transposh) { 33 33 $this->transposh = &$transposh; … … 40 40 // register the callback been used if options of page been submitted and needs to be processed 41 41 add_action('admin_post_save_transposh', array(&$this, 'on_save_changes')); 42 // register a callback to allow admin removal of warnings 43 add_action('wp_ajax_closed_tpwarn', array(&$this, 'on_closed_tpwarn')); 42 // register ajax callbacks 43 add_action('wp_ajax_tp_close_warning', array(&$this, 'on_ajax_tp_close_warning')); 44 add_action('wp_ajax_tp_backup', array(&$this, 'on_ajax_tp_backup')); 45 add_action('wp_ajax_tp_restore', array(&$this, 'on_ajax_tp_restore')); 46 add_action('wp_ajax_tp_maint', array(&$this, 'on_ajax_tp_maint')); 47 add_action('wp_ajax_tp_cleanup', array(&$this, 'on_ajax_tp_cleanup')); 48 add_action('wp_ajax_tp_translate_all', array(&$this, 'on_ajax_tp_translate_all')); 49 add_action('wp_ajax_tp_post_phrases', array(&$this, 'on_ajax_tp_post_phrases')); 44 50 } 45 51 … … 171 177 //TODO - make up my mind on using .css flags here (currently no) 172 178 //if ($this->transposh->options->get_widget_css_flags()) 173 // wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER);179 // wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER); 174 180 wp_enqueue_script('jquery-ui-droppable'); 175 wp_enqueue_script('transposh_control', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcontrol.js', array(), TRANSPOSH_PLUGIN_VER, true); 176 wp_localize_script('transposh_control', 't_jp', array( 177 'post_url' => $this->transposh->post_url, 178 'preferred' => $this->transposh->options->get_preferred_translator(), 179 'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/* 180 /* , 181 'plugin_url' => $this->transposh_plugin_url, 182 'edit' => ($this->edit_mode? '1' : ''), 183 //'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''), 184 'lang' => $this->target_language, 185 // those two options show if the script can support said engines 186 'prefix' => SPAN_PREFIX, 187 'preferred'=> $this->options->get_preferred_translator(), 188 'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '') */ 189 // ,'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};' 190 // need to do this because the way wordpress encodes stuff 191 )); 192 wp_enqueue_script('google', "http://www.google.com/jsapi", array(), '1', true); 193 wp_enqueue_script('transposh_admin', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhadmin.js', array(), TRANSPOSH_PLUGIN_VER, true); 194 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-lightness/jquery-ui.css', array(), '1.8.2'); 195 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js', array('jquery'), '1.8.2', true); 181 wp_enqueue_script('transposh_settings', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhsettings.js', array(), TRANSPOSH_PLUGIN_VER, true); 182 // MAKESURE 3.3+ css 183 // wp_enqueue_script('jquery-ui-progressbar'); 184 185 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 186 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 187 wp_enqueue_script('transposh_backend', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array(), TRANSPOSH_PLUGIN_VER, true); 188 $script_params = array( 189 'l10n_print_after' => 190 't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 191 't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 192 't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 193 ); 194 wp_localize_script("transposh_backend", "t_be", $script_params); 196 195 197 196 //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore … … 322 321 echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>'; 323 322 echo '<div id="tr_loading" style="margin: 0 0 10px 0">' . __('Translate by clicking the button below', TRANSPOSH_TEXT_DOMAIN) . '</div>'; 324 echo '<a id="transposh-translate" href="' . $this->transposh->post_url . '?translate_all&offset=1" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 323 echo '<div id="tr_allmsg" style="margin: 0 0 10px 0"></div>'; 324 echo '<a id="transposh-translate" href="#" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 325 325 //get_posts 326 326 } … … 503 503 */ 504 504 echo '<h4>' . __('MSN API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 505 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) .': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="'.MSN_TRANSLATE_KEY.'" name="'.MSN_TRANSLATE_KEY.'"/>';506 507 /**505 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="' . MSN_TRANSLATE_KEY . '" name="' . MSN_TRANSLATE_KEY . '"/>'; 506 507 /** 508 508 * Allow users to insert their own API keys 509 509 */ 510 510 echo '<h4>' . __('Google API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 511 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) .': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_google_key() . '" id="'.GOOGLE_TRANSLATE_KEY.'" name="'.GOOGLE_TRANSLATE_KEY.'"/>';511 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_google_key() . '" id="' . GOOGLE_TRANSLATE_KEY . '" name="' . GOOGLE_TRANSLATE_KEY . '"/>'; 512 512 513 513 /* … … 593 593 } 594 594 595 function on_closed_tpwarn() { 595 // ajax stuff! 596 function on_ajax_tp_close_warning() { 596 597 $this->transposh->options->set_transposh_admin_hide_warning($_POST['id']); 597 598 $this->transposh->options->update_options(); … … 599 600 } 600 601 602 function on_ajax_tp_backup() { 603 $this->transposh->run_backup(); 604 die(); 605 } 606 607 // Start restore on demand 608 function on_ajax_tp_restore() { 609 $this->transposh->run_restore(); 610 die(); 611 } 612 613 // Start cleanup on demand 614 function on_ajax_tp_cleanup() { 615 $this->transposh->database->cleanup($_POST['days']); 616 die(); 617 } 618 619 // Start maint 620 function on_ajax_tp_maint() { 621 $this->transposh->database->db_maint(); 622 die(); 623 } 624 625 // Start full translation 626 function on_ajax_tp_translate_all() { 627 // get all ids in need of translation 628 global $wpdb; 629 $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC"); 630 // only high capabilities users can... 631 // add a fake post to translate things such as tags 632 if (!current_user_can('edit_post', $page_ids[0])) return; 633 $page_ids[] = "-555"; 634 echo json_encode($page_ids); 635 die(); 636 } 637 638 // getting phrases of a post (if we are in admin) 639 function on_ajax_tp_post_phrases() { 640 $this->transposh->postpublish->get_post_phrases($_GET['post']); 641 die(); 642 } 643 601 644 } 602 645 -
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r599 r667 15 15 * This file handles various AJAX needs of our plugin 16 16 */ 17 // The following headers allow for cross-domain posting here, which is useful for some weird sites18 header('Access-Control-Allow-Origin: *');19 header('Access-Control-Allow-Methods: GET, POST, OPTIONS');20 header('Access-Control-Allow-Headers: X-Requested-With');21 header('Access-Control-Max-Age: 86400');22 17 23 // Exit early so the page isn't fully loaded for options requests 24 if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { 25 exit(); 26 } 18 echo "This file was removed in 0.8.0 and is only kept for debugging"; 27 19 28 // we need wordpress and us...29 $root = $_SERVER["DOCUMENT_ROOT"];30 $self = $_SERVER["SCRIPT_NAME"];31 // go down 4 dirs...32 for ($i = 0; $i < 5; $i++)33 $self = substr($self, 0, -strlen(strrchr($self, '/')));34 if (file_exists($root . $self . '/wp-load.php')) {35 require_once $root . $self . '/wp-load.php';36 } else {37 // fallback plan38 require_once('../../../../wp-load.php');39 }40 // the case of posted translation41 if (isset($_POST['translation_posted'])) {42 do_action('transposh_translation_posted');43 $my_transposh_plugin->database->update_translation();44 }45 // getting translation history46 elseif (isset($_GET['tr_token_hist'])) {47 // deleting48 if (isset($_GET['action']) && $_GET['action'] == 'delete') {49 $my_transposh_plugin->database->del_translation_history($_GET['tr_token_hist'], $_GET['lang'], $_GET['timestamp']);50 }51 $my_transposh_plugin->database->get_translation_history($_GET['tr_token_hist'], $_GET['lang']);52 }53 // getting translation alternates54 elseif (isset($_GET['tr_token_alt'])) {55 $my_transposh_plugin->database->get_translation_alt($_GET['tr_token_alt']);56 }57 // getting phrases of a post (if we are in admin)58 elseif (isset($_GET['tr_phrases_post'])) {59 $my_transposh_plugin->postpublish->get_post_phrases($_GET['post']);60 }61 // set the cookie with ajax, no redirect needed62 elseif (isset($_GET['tr_cookie'])) {63 setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);64 logger('Cookie ' . transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url));65 }66 // Set our cookie and return (if no js works - or we are in the default language)67 elseif (isset($_GET['tr_cookie_bck'])) {68 setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);69 if ($_SERVER['HTTP_REFERER']) {70 $this->transposh->tp_redirect($_SERVER['HTTP_REFERER']);71 } else {72 $this->transposh->tp_redirect($my_transposh_plugin->home_url);73 }74 }75 // Start full translation76 elseif (isset($_GET['translate_all'])) {77 // get all ids in need of translation78 $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC");79 // only high capabilities users can...80 if (!current_user_can('edit_post', $page_ids[0])) return;81 // add a fake post to translate things such as tags82 $page_ids[] = "-555";83 echo json_encode($page_ids);84 }85 // Proxyed translation for google translate86 elseif (isset($_GET['tgp'])) {87 // we need curl for this proxy88 if (!function_exists('curl_init')) return;89 // we want to avoid unneeded work or dos attacks on languages we don't support90 if (!in_array($_GET['tgl'], transposh_consts::$google_proxied_languages) || !$my_transposh_plugin->options->is_editable_language($_GET['tgl']))91 return;92 $url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto';93 $ch = curl_init();94 curl_setopt($ch, CURLOPT_URL, $url);95 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);96 //must set agent for google to respond with utf-897 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');98 $output = curl_exec($ch);99 curl_close($ch);100 header('Content-type: text/html; charset=utf-8');101 echo $output;102 }103 // Start backup on demand104 elseif (isset($_GET['backup'])) {105 $my_transposh_plugin->run_backup();106 }107 // Start restore on demand108 elseif (isset($_GET['restore'])) {109 $my_transposh_plugin->run_restore();110 }111 // Start cleanup on demand112 elseif (isset($_GET['cleanup'])) {113 // just make sure the admin started this... recently enough114 check_ajax_referer('transposh-clean', 'nonce');115 $my_transposh_plugin->database->cleanup($_GET['days']);116 }117 // Start maint118 elseif (isset($_GET['maint'])) {119 // just make sure the admin started this... recently enough120 check_ajax_referer('transposh-clean', 'nonce');121 $my_transposh_plugin->database->db_maint();122 }123 20 ?> -
trunk/WordPress/plugin/transposh/wp/transposh_backup.php
r506 r667 47 47 return; 48 48 } 49 if ( $result['headers']['fail']) {49 if (isset($result['headers']['fail'])) { 50 50 echo '500 - ' . $result['headers']['fail']; 51 51 return; … … 57 57 $this->transposh->options->update_options(); 58 58 } 59 if ( $result['headers']['lastitem']) {59 if (isset($result['headers']['lastitem'])) { 60 60 $rowstosend = $this->transposh->database->get_all_human_translation_history($result['headers']['lastitem'], 500); 61 61 while ($rowstosend) { … … 82 82 return; 83 83 } 84 if ( $result['headers']['fail']) {84 if (isset($result['headers']['fail'])) { 85 85 echo "500 - " . $result['headers']['fail']; 86 86 return; -
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r661 r667 69 69 //@$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) or $this->memcache_working = false; 70 70 } */ 71 logger($this->memcache_working); 71 logger($this->memcache_working); // TODO!! make sure it does something 72 72 } 73 73 … … 604 604 */ 605 605 function get_all_human_translation_history($date ="null", $limit = "") { 606 $limitterm = ''; 607 $dateterm = ''; 606 608 if ($date != "null") 607 609 $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date"; -
trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php
r652 r667 23 23 /** @var transposh_plugin Container class */ 24 24 private $transposh; 25 25 26 /** @var boolean Did we just edited/saved? */ 26 27 private $just_published = false; … … 53 54 if (!isset($_GET['post'])) return; 54 55 if (get_post_meta($_GET['post'], 'transposh_can_translate', true)) { // do isdefined stuff 55 $this->just_published = true; // this is later used in the meta boxes 56 wp_enqueue_script("transposhadmin", $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhadmin.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 57 wp_localize_script("transposhadmin", "t_jp", array( 58 'post_url' => $this->transposh->post_url, 56 $this->just_published = true; // this is later used in the meta boxes //XXXXXXXXXXXXXXXXXXXXXXXXXXXX 57 wp_enqueue_script("transposh_backend", $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 58 $script_params = array( 59 59 'post' => $_GET['post'], 60 'preferred' => $this->transposh->options->get_preferred_translator(), 61 'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' 62 )); 63 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/ui-lightness/jquery-ui.css', array(), '1.8.14'); 64 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js', array('jquery'), '1.8.14', true); 60 'l10n_print_after' => 61 't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 62 't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 63 't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 64 ); 65 wp_localize_script("transposh_backend", "t_be", $script_params); 66 // MAKESURE 3.3 67 // wp_enqueue_script('jquery-ui-progressbar'); 68 69 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 70 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 71 65 72 delete_post_meta($_GET['post'], 'transposh_can_translate'); // as we have used the meta - it can go now, another option would have been to put this in the getphrases 66 73 } … … 86 93 function get_post_phrases($postID) { 87 94 // Some security, to avoid others from seeing private posts 88 if (!current_user_can('edit_post', $postID)) return;89 95 // fake post for tags 90 96 if ($postID == -555) { … … 94 100 // a normal post 95 101 else { 102 if (!current_user_can('edit_post', $postID)) return; 103 global $post; // thid is needed because some of the functions below expect it... 96 104 $post = get_post($postID); 97 105 // Display filters … … 127 135 } 128 136 } 137 // We provide the post title here 138 $json['posttitle'] = $title; 139 // and all languages we might want to target 140 $json['langs'] = array(); 141 129 142 foreach ($phrases as $key) { 130 143 foreach (explode(',', $this->transposh->options->get_editable_langs()) as $lang) { … … 133 146 if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) { 134 147 // There is no point in returning phrases, languages pairs that cannot be translated 135 if (in_array($lang, transposh_consts::$bing_languages) || in_array($lang, transposh_consts::$google_languages)) { 148 if (in_array($lang, transposh_consts::$bing_languages) || 149 in_array($lang, transposh_consts::$google_languages) || 150 in_array($lang, transposh_consts::$apertium_languages)) { 136 151 list($source, $translation) = $this->transposh->database->fetch_translation($key, $lang); 137 152 if (!$translation) { … … 141 156 } 142 157 array_push($json['p'][$key]['l'], $lang); 158 if (!in_array($lang, $json['langs'])) { 159 array_push($json['langs'], $lang); 160 } 143 161 } 144 162 } … … 152 170 } 153 171 154 // add the title155 // if ($json['length'])156 $json['posttitle'] = $title;157 172 158 173 // the header helps with debugging -
trunk/WordPress/plugin/transposh/wp/transposh_widget.php
r659 r667 223 223 if ($this->transposh->options->get_widget_allow_set_default_language()) { 224 224 If ((isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language) || (!isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language))) { 225 echo '<a id="' . SPAN_PREFIX . 'setdeflang" onClick="return false;" href="' . $this->transposh->post_url . '?tr_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>';225 echo '<a id="' . SPAN_PREFIX . 'setdeflang" onClick="return false;" href="' . admin_url('admin-ajax.php') . '?action=tp_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 226 226 } 227 227 }
Note: See TracChangeset
for help on using the changeset viewer.
