Transposh WordPress Translation - Version 0.3.8

Version Description

Download this release

Release Info

Developer oferwald
Plugin Icon 128x128 Transposh WordPress Translation
Version 0.3.8
Comparing to
See all releases

Code changes from version 0.3.7 to 0.3.8

core/constants.php CHANGED
@@ -91,7 +91,7 @@ $rtl_languages = array("ar", "he", "fa", "yi");
91
  //Define the new capability that will be assigned to roles - translator
92
  define("TRANSLATOR", 'translator');
93
 
94
- define("TRANSPOSH_PLUGIN_VER",'0.3.7');
95
 
96
  //Define segment id prefix, will be included in span tag. also used as class identifier
97
  define("SPAN_PREFIX", "tr_");
91
  //Define the new capability that will be assigned to roles - translator
92
  define("TRANSLATOR", 'translator');
93
 
94
+ define("TRANSPOSH_PLUGIN_VER",'0.3.8');
95
 
96
  //Define segment id prefix, will be included in span tag. also used as class identifier
97
  define("SPAN_PREFIX", "tr_");
core/parser.php CHANGED
@@ -37,8 +37,8 @@ class parser {
37
  public $is_edit_mode;
38
  public $is_auto_translate;
39
  public $feed_fix;
40
- //first three are html, later 4 come from feeds xml
41
- protected $ignore_tags = array('script'=>1, 'style'=>1, 'code'=>1,'link'=>1,'wfw:commentrss'=>1,'comments'=>1,'guid'=>1);
42
  /**
43
  * Determine if the current position in buffer is a white space.
44
  * @param char $char
@@ -203,6 +203,7 @@ class parser {
203
  function tag_phrase($string,$start, $end) {
204
  $phrase = trim(substr($string,$start,$end-$start));
205
  if ($phrase) {
 
206
  $node = new simple_html_dom_node($this->html);
207
  $node->tag = 'phrase';
208
  $node->parent = $this->currentnode;
@@ -247,7 +248,10 @@ class parser {
247
  }
248
  // we have a special case for <> tags which might have came to us (maybe in xml feeds) (we'll skip them...)
249
  elseif ($string[$pos] == '<') {
 
250
  while ($string[$pos] != '>' && $pos < strlen($string)) $pos ++;
 
 
251
  }
252
  // will break translation unit when there's a breaker ",.[]()..."
253
  elseif($senb_len = $this->is_sentence_breaker($string[$pos],$string[$pos+1],$string[$pos+2])) {
@@ -270,7 +274,7 @@ class parser {
270
 
271
  // the end is also some breaker
272
  if($pos > $start) {
273
- $this->tag_phrase($string,$start,$pos);
274
  }
275
  }
276
 
@@ -293,6 +297,10 @@ class parser {
293
  if ($node->parent->tag == 'a' && $node->parent->href == $node->outertext) {
294
  return;
295
  }
 
 
 
 
296
  if (trim($node->outertext)) {
297
  $this->parsetext($node->outertext);
298
  }
@@ -399,12 +407,19 @@ class parser {
399
  }
400
  // guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
401
  foreach ($this->html->find('guid') as $e) {
402
- $e->innertext = $e->innertext.'-'.$this->lang;
403
- unset($e->nodes);
404
  }
405
  // fix feed language
406
  $this->html->find('language', 0)->innertext = $this->lang;
407
  unset($this->html->find('language', 0)->nodes);
 
 
 
 
 
 
 
408
  }
409
 
410
  // actually translate tags
@@ -459,7 +474,7 @@ class parser {
459
  if ($e->parent->_[HDOM_INFO_OUTER]) {
460
  $saved_outertext = $e->outertext;
461
  }
462
-
463
  foreach ($e->nodes as $ep) {
464
  if ($ep->tag == 'phrase') {
465
  list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func,array($ep->phrase, $this->lang));
37
  public $is_edit_mode;
38
  public $is_auto_translate;
39
  public $feed_fix;
40
+ //first three are html, later 3 come from feeds xml (link is problematic...)
41
+ protected $ignore_tags = array('script'=>1, 'style'=>1, 'code'=>1,'wfw:commentrss'=>1,'comments'=>1,'guid'=>1);
42
  /**
43
  * Determine if the current position in buffer is a white space.
44
  * @param char $char
203
  function tag_phrase($string,$start, $end) {
204
  $phrase = trim(substr($string,$start,$end-$start));
205
  if ($phrase) {
206
+
207
  $node = new simple_html_dom_node($this->html);
208
  $node->tag = 'phrase';
209
  $node->parent = $this->currentnode;
248
  }
249
  // we have a special case for <> tags which might have came to us (maybe in xml feeds) (we'll skip them...)
250
  elseif ($string[$pos] == '<') {
251
+ $this->tag_phrase($string,$start,$pos);
252
  while ($string[$pos] != '>' && $pos < strlen($string)) $pos ++;
253
+ $pos++;
254
+ $start = $pos;
255
  }
256
  // will break translation unit when there's a breaker ",.[]()..."
257
  elseif($senb_len = $this->is_sentence_breaker($string[$pos],$string[$pos+1],$string[$pos+2])) {
274
 
275
  // the end is also some breaker
276
  if($pos > $start) {
277
+ $this->tag_phrase($string,$start,$pos);
278
  }
279
  }
280
 
297
  if ($node->parent->tag == 'a' && $node->parent->href == $node->outertext) {
298
  return;
299
  }
300
+ // link tags inners are to be ignored
301
+ if ($node->parent->tag == 'link') {
302
+ return;
303
+ }
304
  if (trim($node->outertext)) {
305
  $this->parsetext($node->outertext);
306
  }
407
  }
408
  // guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
409
  foreach ($this->html->find('guid') as $e) {
410
+ $e->innertext = $e->innertext.'-'.$this->lang;
411
+ unset($e->nodes);
412
  }
413
  // fix feed language
414
  $this->html->find('language', 0)->innertext = $this->lang;
415
  unset($this->html->find('language', 0)->nodes);
416
+ } else {
417
+ // since this is not a feed, we might have references to such in the <link rel="alternate">
418
+ foreach ($this->html->find('link') as $e) {
419
+ if (strcasecmp($e->rel, 'alternate') == 0 || strcasecmp($e->rel, 'canonical') == 0) {
420
+ $e->href = call_user_func_array($this->url_rewrite_func,array($e->href));
421
+ }
422
+ }
423
  }
424
 
425
  // actually translate tags
474
  if ($e->parent->_[HDOM_INFO_OUTER]) {
475
  $saved_outertext = $e->outertext;
476
  }
477
+
478
  foreach ($e->nodes as $ep) {
479
  if ($ep->tag == 'phrase') {
480
  list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func,array($ep->phrase, $this->lang));
core/utils.php CHANGED
@@ -14,7 +14,7 @@
14
  * You should have received a copy of the GNU General Public License
15
  * along with this program; if not, write to the Free Software
16
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
- */
18
 
19
  /**
20
  *
@@ -28,9 +28,9 @@ require_once("constants.php");
28
  /*
29
  * Remove from url any language (or editing) params that were added for our use.
30
  * Return the scrubed url
31
- */
32
  function cleanup_url($url, $home_url, $remove_host = false) {
33
-
34
  $parsedurl = @parse_url($url);
35
  //cleanup previous lang & edit parameter from url
36
 
@@ -56,7 +56,7 @@ function cleanup_url($url, $home_url, $remove_host = false) {
56
  $parsedurl['path'] = substr($parsedurl['path'],strlen($home_path));
57
  $gluebackhome = true;
58
  }
59
-
60
  if (strlen($parsedurl['path']) > 2) {
61
  $secondslashpos = strpos($parsedurl['path'], "/",1);
62
  if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
@@ -141,7 +141,7 @@ function rewrite_url_lang_param($url,$home_url, $enable_permalinks_rewrite, $lan
141
  if (!$parsedurl['path']) $parsedurl['path'] = "/";
142
  $parsedurl['path'] = "/".$lang.$parsedurl['path'];
143
  }
144
- if ($gluebackhome) $parsedurl['path'] = $home_path.$parsedurl['path'];
145
 
146
  //insert params to url
147
  if(isset($params) && $params) {
@@ -216,7 +216,7 @@ function glue_url($parsed) {
216
 
217
  if (isset($parsed['path'])) {
218
  $uri .= (substr($parsed['path'], 0, 1) == '/') ?
219
- $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
220
  }
221
 
222
  $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';
@@ -255,4 +255,57 @@ function display_flag ($path, $flag, $language, $css = false) {
255
  }
256
  }
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  ?>
14
  * You should have received a copy of the GNU General Public License
15
  * along with this program; if not, write to the Free Software
16
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
 
19
  /**
20
  *
28
  /*
29
  * Remove from url any language (or editing) params that were added for our use.
30
  * Return the scrubed url
31
+ */
32
  function cleanup_url($url, $home_url, $remove_host = false) {
33
+
34
  $parsedurl = @parse_url($url);
35
  //cleanup previous lang & edit parameter from url
36
 
56
  $parsedurl['path'] = substr($parsedurl['path'],strlen($home_path));
57
  $gluebackhome = true;
58
  }
59
+
60
  if (strlen($parsedurl['path']) > 2) {
61
  $secondslashpos = strpos($parsedurl['path'], "/",1);
62
  if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
141
  if (!$parsedurl['path']) $parsedurl['path'] = "/";
142
  $parsedurl['path'] = "/".$lang.$parsedurl['path'];
143
  }
144
+ if ($gluebackhome) $parsedurl['path'] = $home_path.$parsedurl['path'];
145
 
146
  //insert params to url
147
  if(isset($params) && $params) {
216
 
217
  if (isset($parsed['path'])) {
218
  $uri .= (substr($parsed['path'], 0, 1) == '/') ?
219
+ $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
220
  }
221
 
222
  $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';
255
  }
256
  }
257
 
258
+ /**
259
+ * determine which language out of an available set the user prefers most
260
+ * adapted from php documentation page
261
+ * @param array $available_languages array with language-tag-strings (must be lowercase) that are available
262
+ * @param string $default_lang Language that will be default (first in available languages if not provided)
263
+ * @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out)
264
+ * @return string
265
+ */
266
+ function prefered_language ($available_languages,$default_lang="auto",$http_accept_language="auto") {
267
+ // if $http_accept_language was left out, read it from the HTTP-Header
268
+ if ($http_accept_language == "auto") $http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
269
+
270
+ // standard for HTTP_ACCEPT_LANGUAGE is defined under
271
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
272
+ // pattern to find is therefore something like this:
273
+ // 1#( language-range [ ";" "q" "=" qvalue ] )
274
+ // where:
275
+ // language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
276
+ // qvalue = ( "0" [ "." 0*3DIGIT ] )
277
+ // | ( "1" [ "." 0*3("0") ] )
278
+ preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" .
279
+ "(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i",
280
+ $http_accept_language, $hits, PREG_SET_ORDER);
281
+
282
+ // default language (in case of no hits) is the first in the array
283
+ if ($default_lang=='auto') $bestlang = $available_languages[0]; else $bestlang = $default_lang;
284
+ $bestqval = 0;
285
+
286
+ foreach ($hits as $arr) {
287
+ // read data from the array of this hit
288
+ $langprefix = strtolower ($arr[1]);
289
+ if (!empty($arr[3])) {
290
+ $langrange = strtolower ($arr[3]);
291
+ $language = $langprefix . "-" . $langrange;
292
+ }
293
+ else $language = $langprefix;
294
+ $qvalue = 1.0;
295
+ if (!empty($arr[5])) $qvalue = floatval($arr[5]);
296
+
297
+ // find q-maximal language
298
+ if (in_array($language,$available_languages) && ($qvalue > $bestqval)) {
299
+ $bestlang = $language;
300
+ $bestqval = $qvalue;
301
+ }
302
+ // if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does)
303
+ else if (in_array($languageprefix,$available_languages) && (($qvalue*0.9) > $bestqval)) {
304
+ $bestlang = $languageprefix;
305
+ $bestqval = $qvalue*0.9;
306
+ }
307
+ }
308
+ return $bestlang;
309
+ }
310
+
311
  ?>
js/transposh.js CHANGED
@@ -1 +1 @@
1
- function getgt(){jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");google.language.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",transposh_params.lang,function(a){if(!a.error){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+a.translation+"</div>").text()).keyup()}})}function getbt(){jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled");var a=transposh_params.lang;if(a=="zh"){a="zh-chs"}if(a=="zh-tw"){a="zh-cht"}Microsoft.Translator.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",a,function(b){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+b+"</div>").text()).keyup()})}var done_p=0;var togo=0;var timer;function do_timer(a){alert("timer..."+a)}var tokens=new Array();var translations=new Array();function ajax_translate(c,b,a){clearTimeout(timer);tokens.push(jQuery("#"+transposh_params.prefix+a).attr("token"));translations.push(c);fix_page(c,b,a);timer=setTimeout(function(){var e={lang:transposh_params.lang,source:b,translation_posted:"1",items:tokens.length};for(var d=0;d<tokens.length;d++){e["tk"+d]=tokens[d];e["tr"+d]=translations[d];if(b>0){done_p+=jQuery("*[token='"+tokens[d]+"']").size()}}jQuery.ajax({type:"POST",url:transposh_params.post_url,data:e,success:function(){if(transposh_params.progress){if(togo>4&&b>0){jQuery("#progress_bar2").progressbar("value",done_p/togo*100)}}},error:function(f){if(b==0){alert("Error !!! failed to translate.\n\nServer's message: "+f.statusText)}}});translations=[];tokens=[]},200)}function fix_page(e,d,c){var b=jQuery("#"+transposh_params.prefix+c).attr("token");var a=e;if(jQuery.trim(e).length===0){a=jQuery("#"+transposh_params.prefix+c).attr("orig")}jQuery("*[token='"+b+"'][hidden!='y']").html(a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}});jQuery("*[token='"+b+"'][hidden='y']").attr("trans",a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}})}function do_auto_translate(){if(transposh_params.progress){togo=jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#"+transposh_params.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery("#progress_bar2 > div").css({background:"#28F828",border:"#08A908 1px solid"})}var a=0}var b=new Array();jQuery("."+transposh_params.prefix+'[source=""]').each(function(d){var c=jQuery(this).attr("id");var e=jQuery(this).attr("orig");if(e==undefined){e=jQuery(this).html()}if(!(b[e]==1)){b[e]=1;google.language.translate(e,"",transposh_params.lang,function(f){if(!f.error){var g=c.substr(c.lastIndexOf("_")+1);ajax_translate(jQuery("<div>"+f.translation+"</div>").text(),1,g);if(transposh_params.progress){a=togo-jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#progress_bar").progressbar("value",a/togo*100)}}}})}})}function confirm_close(){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({bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery(this).dialog("close");jQuery("#"+transposh_params.prefix+"d-tabs").dialog("close")},Cancel:function(){jQuery(this).dialog("close")}}})}function translate_dialog(b){jQuery("#"+transposh_params.prefix+"d-tabs").remove();jQuery('<div id="'+transposh_params.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");jQuery("#"+transposh_params.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+transposh_params.prefix+"d-tabs-1","Translate").tabs("add",transposh_params.post_url+"?tr_token_hist="+jQuery("#"+transposh_params.prefix+b).attr("token")+"&lang="+transposh_params.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(d,e){jQuery("table",e.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});jQuery("table thead tr",e.panel).addClass("ui-widget-header");jQuery("table tbody td[source='1']",e.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');jQuery("table tbody td[source='0']",e.panel).append('<span title="human" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-person"></span>')}).bind("tabsselect",function(d,e){if(jQuery(e.tab).text()=="Translate"){jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",a)}else{jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",c)}}).bind("dialogbeforeclose",function(d,e){if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){confirm_close();return false}return true});jQuery("#"+transposh_params.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside");jQuery("#"+transposh_params.prefix+"d-tabs-1").css("padding","1px").append('<form id="'+transposh_params.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+transposh_params.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/><label for="translation">Translate To</label><textarea cols="80" row="3" name="translation" id="'+transposh_params.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');jQuery("#"+transposh_params.prefix+"d-tabs-1 label").css("display","block");jQuery("#"+transposh_params.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});jQuery("#"+transposh_params.prefix+"original").val(jQuery("#"+transposh_params.prefix+b).attr("orig"));jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).html());if(jQuery("#"+transposh_params.prefix+b).attr("trans")){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).attr("trans"))}jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery("#"+transposh_params.prefix+"translation").keyup(function(d){if(jQuery("#"+transposh_params.prefix+b).text()!=jQuery(this).val()){jQuery(this).css("background","yellow");jQuery(this).data("edit",{changed:true})}else{jQuery(this).css("background","");jQuery(this).data("edit",{changed:false})}});var a={};if(binglangs.indexOf(transposh_params.lang+",",0)>-1){a["Suggest - Bing"]=function(){getbt()}}if(google.language.isTranslatable(transposh_params.lang)||ext_langs.indexOf(transposh_params.lang)>-1){a["Suggest - Google"]=function(){getgt()}}a.Ok=function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")};var c={Close:function(){jQuery(this).dialog("close")}};jQuery("#"+transposh_params.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:a})}jQuery.noConflict();var transposh_params=new Array();var ext_langs="he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi";jQuery("script[src*='transposh.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});google.load("language","1");var binglangs="";if(typeof(Microsoft)!="undefined"){try{binglangs=String(Microsoft.Translator.GetLanguages())+",zh,zh-tw,"}catch(err){alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")")}}jQuery(document).ready(function(){if(typeof(jQuery().progressbar)!="undefined"){transposh_params.progress=true}if(google.language.isTranslatable(transposh_params.lang)||ext_langs.indexOf(transposh_params.lang)>-1){do_auto_translate()}if(transposh_params.edit){jQuery("."+transposh_params.prefix).each(function(c){var a=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery(this).after('<span id="'+transposh_params.prefix+"img_"+a+'" class="tr-icon" title="'+jQuery(this).attr("orig")+'"></span>');var b=jQuery("#"+transposh_params.prefix+"img_"+a);b.click(function(){translate_dialog(a);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(jQuery(this).attr("source")=="1"){b.addClass("tr-icon-yellow")}else{if(jQuery(this).attr("source")=="0"){b.addClass("tr-icon-green")}}if(jQuery(this).attr("hidden")=="y"){b.css({opacity:"0.6"})}})}});
1
+ function getgt(){jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");google.language.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",transposh_params.lang,function(a){if(!a.error){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+a.translation+"</div>").text()).keyup()}})}function getbt(){jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled");var a=transposh_params.lang;if(a=="zh"){a="zh-chs"}if(a=="zh-tw"){a="zh-cht"}Microsoft.Translator.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",a,function(b){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+b+"</div>").text()).keyup()})}var done_p=0;var togo=0;var timer;var tokens=new Array();var translations=new Array();function ajax_translate(c,b,a){clearTimeout(timer);tokens.push(jQuery("#"+transposh_params.prefix+a).attr("token"));translations.push(c);fix_page(c,b,a);timer=setTimeout(function(){var e={lang:transposh_params.lang,source:b,translation_posted:"1",items:tokens.length};for(var d=0;d<tokens.length;d++){e["tk"+d]=tokens[d];e["tr"+d]=translations[d];if(b>0){done_p+=jQuery("*[token='"+tokens[d]+"']").size()}}jQuery.ajax({type:"POST",url:transposh_params.post_url,data:e,success:function(){if(transposh_params.progress){if(togo>4&&b>0){jQuery("#progress_bar2").progressbar("value",done_p/togo*100)}}},error:function(f){if(b==0){alert("Error !!! failed to translate.\n\nServer's message: "+f.statusText)}}});translations=[];tokens=[]},200)}function fix_page(e,d,c){var b=jQuery("#"+transposh_params.prefix+c).attr("token");var a=e;if(jQuery.trim(e).length===0){a=jQuery("#"+transposh_params.prefix+c).attr("orig")}jQuery("*[token='"+b+"'][hidden!='y']").html(a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}});jQuery("*[token='"+b+"'][hidden='y']").attr("trans",a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}})}function do_auto_translate(){if(transposh_params.progress){togo=jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#"+transposh_params.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery("#progress_bar2 > div").css({background:"#28F828",border:"#08A908 1px solid"})}var a=0}var b=new Array();jQuery("."+transposh_params.prefix+'[source=""]').each(function(d){var c=jQuery(this).attr("id");var e=jQuery(this).attr("orig");if(e==undefined){e=jQuery(this).html()}if(!(b[e]==1)){b[e]=1;google.language.translate(e,"",transposh_params.lang,function(f){if(!f.error){var g=c.substr(c.lastIndexOf("_")+1);ajax_translate(jQuery("<div>"+f.translation+"</div>").text(),1,g);if(transposh_params.progress){a=togo-jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#progress_bar").progressbar("value",a/togo*100)}}}})}})}function confirm_close(){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({bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery(this).dialog("close");jQuery("#"+transposh_params.prefix+"d-tabs").dialog("close")},Cancel:function(){jQuery(this).dialog("close")}}})}function translate_dialog(b){jQuery("#"+transposh_params.prefix+"d-tabs").remove();jQuery('<div id="'+transposh_params.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");jQuery("#"+transposh_params.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+transposh_params.prefix+"d-tabs-1","Translate").tabs("add",transposh_params.post_url+"?tr_token_hist="+jQuery("#"+transposh_params.prefix+b).attr("token")+"&lang="+transposh_params.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(d,e){jQuery("table",e.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});jQuery("table thead tr",e.panel).addClass("ui-widget-header");jQuery("table tbody td[source='1']",e.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');jQuery("table tbody td[source='0']",e.panel).append('<span title="human" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-person"></span>')}).bind("tabsselect",function(d,e){if(jQuery(e.tab).text()=="Translate"){jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",a)}else{jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",c)}}).bind("dialogbeforeclose",function(d,e){if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){confirm_close();return false}return true});jQuery("#"+transposh_params.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside");jQuery("#"+transposh_params.prefix+"d-tabs-1").css("padding","1px").append('<form id="'+transposh_params.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+transposh_params.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/><label for="translation">Translate To</label><textarea cols="80" row="3" name="translation" id="'+transposh_params.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');jQuery("#"+transposh_params.prefix+"d-tabs-1 label").css("display","block");jQuery("#"+transposh_params.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});jQuery("#"+transposh_params.prefix+"original").val(jQuery("#"+transposh_params.prefix+b).attr("orig"));jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).html());if(jQuery("#"+transposh_params.prefix+b).attr("trans")){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).attr("trans"))}jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery("#"+transposh_params.prefix+"translation").keyup(function(d){if(jQuery("#"+transposh_params.prefix+b).text()!=jQuery(this).val()){jQuery(this).css("background","yellow");jQuery(this).data("edit",{changed:true})}else{jQuery(this).css("background","");jQuery(this).data("edit",{changed:false})}});var a={};if(binglangs.indexOf(transposh_params.lang+",",0)>-1){a["Suggest - Bing"]=function(){getbt()}}if(google.language.isTranslatable(transposh_params.lang)||ext_langs.indexOf(transposh_params.lang)>-1){a["Suggest - Google"]=function(){getgt()}}a.Ok=function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")};var c={Close:function(){jQuery(this).dialog("close")}};jQuery("#"+transposh_params.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:a})}jQuery.noConflict();var transposh_params=new Array();var ext_langs="he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi";jQuery("script[src*='transposh.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});google.load("language","1");var binglangs="";if(typeof(Microsoft)!="undefined"){try{binglangs=String(Microsoft.Translator.GetLanguages())+",zh,zh-tw,"}catch(err){alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")")}}jQuery(document).ready(function(){if(typeof(jQuery().progressbar)!="undefined"){transposh_params.progress=true}jQuery("#"+transposh_params.prefix+"setdeflang").click(function(){jQuery.get(transposh_params.post_url+"?tr_cookie="+Math.random());jQuery(this).hide("slow");return false});if(google.language.isTranslatable(transposh_params.lang)||ext_langs.indexOf(transposh_params.lang)>-1){do_auto_translate()}if(transposh_params.edit){jQuery("."+transposh_params.prefix).each(function(c){var a=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery(this).after('<span id="'+transposh_params.prefix+"img_"+a+'" class="tr-icon" title="'+jQuery(this).attr("orig")+'"></span>');var b=jQuery("#"+transposh_params.prefix+"img_"+a);b.click(function(){translate_dialog(a);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(jQuery(this).attr("source")=="1"){b.addClass("tr-icon-yellow")}else{if(jQuery(this).attr("source")=="0"){b.addClass("tr-icon-green")}}if(jQuery(this).attr("hidden")=="y"){b.css({opacity:"0.6"})}})}});
js/transposhadmin.js CHANGED
@@ -1 +1 @@
1
- var timer;var items=0;var translations=[];var tokens=[];var langs=[];function ajax_translate_me(a,c,b){clearTimeout(timer);items++;tokens.push(a);translations.push(c);langs.push(b);timer=setTimeout(function(){var e={sr0:1,translation_posted:"2",items:items};for(var d=0;d<items;d++){if(tokens[d]!=tokens[d-1]){e["tk"+d]=tokens[d]}if(langs[d]!=langs[d-1]){e["ln"+d]=langs[d]}if(translations[d]!=translations[d-1]){e["tr"+d]=translations[d]}}jQuery.ajax({type:"POST",url:transposh_params.post_url,data:e,success:function(){},error:function(f){}});translations=[];tokens=[];langs=[]},200)}jQuery.noConflict();google.load("language","1");var transposh_params=new Array();var ext_langs="he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi";jQuery("script[src*='transposhadmin.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});jQuery(document).ready(function(){var c=0;var a="";var b=0;jQuery.getJSON(transposh_params.post_url+"?tr_phrases_post=y&post="+transposh_params.post,function(d){if(d==null){jQuery("#tr_loading").replaceWith("Nothing left to translate");return}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>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery.each(d.p,function(e,f){jQuery("#progress_bar2").progressbar("value",b/f.l.length*100);jQuery.each(f.l,function(h,g){google.language.translate(e,"",g,function(i){if(!i.error){if(a!=e){a=e;b=0;c++}jQuery("#progress_bar").progressbar("value",c/d.length*100);b++;jQuery("#progress_bar2").progressbar("value",b/f.l.length*100);jQuery("#p").text(jQuery("<div>"+e+"</div>").text());jQuery("#l").text(g);jQuery("#r").text(jQuery("<div>"+i.translation+"</div>").text());ajax_translate_me(f.t,jQuery("<div>"+i.translation+"</div>").text(),g)}})})})})});
1
+ var timer;var items=0;var translations=[];var tokens=[];var langs=[];function ajax_translate_me(a,c,b){clearTimeout(timer);items++;tokens.push(a);translations.push(c);langs.push(b);timer=setTimeout(function(){var e={sr0:1,translation_posted:"2",items:items};for(var d=0;d<items;d++){if(tokens[d]!=tokens[d-1]){e["tk"+d]=tokens[d]}if(langs[d]!=langs[d-1]){e["ln"+d]=langs[d]}if(translations[d]!=translations[d-1]){e["tr"+d]=translations[d]}}jQuery.ajax({type:"POST",url:transposh_params.post_url,data:e,success:function(){},error:function(f){}});translations=[];tokens=[];langs=[]},200)}jQuery.noConflict();google.load("language","1");var transposh_params=new Array();var ext_langs="he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi";jQuery("script[src*='transposhadmin.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});jQuery(document).ready(function(){var c=0;var a="";var b=0;jQuery.getJSON(transposh_params.post_url+"?tr_phrases_post=y&post="+transposh_params.post+"&random="+Math.random(),function(d){if(d==null){jQuery("#tr_loading").replaceWith("Nothing left to translate");return}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>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery.each(d.p,function(e,f){jQuery("#progress_bar2").progressbar("value",b/f.l.length*100);jQuery.each(f.l,function(h,g){google.language.translate(e,"",g,function(i){if(!i.error){if(a!=e){a=e;b=0;c++}jQuery("#progress_bar").progressbar("value",c/d.length*100);b++;jQuery("#progress_bar2").progressbar("value",b/f.l.length*100);jQuery("#p").text(jQuery("<div>"+e+"</div>").text());jQuery("#l").text(g);jQuery("#r").text(jQuery("<div>"+i.translation+"</div>").text());ajax_translate_me(f.t,jQuery("<div>"+i.translation+"</div>").text(),g)}})})})})});
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: oferwald, amirperlman
3
  Donate link: http://transposh.org/donate/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
- Tested up to: 2.8.6
7
- Stable tag: 0.3.7
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
@@ -52,7 +52,7 @@ In the languages array in the constants.php file change the two letter ISO code
52
 
53
  = I have a feature to suggest =
54
 
55
- The correct place for that would be our [development site](http://trac.transposh.com "ticket system")
56
 
57
  = The interface looks messed up =
58
 
@@ -120,6 +120,11 @@ change the .css from transparent background to your page background color. And l
120
  5. Widget style selection
121
 
122
  == Changelog ==
 
 
 
 
 
123
  = 2009/12/06 - 0.3.7 =
124
  * Fix feed parsing
125
  * Fix issue with parsing numbers before sentence breakers
3
  Donate link: http://transposh.org/donate/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
+ Tested up to: 2.9.0
7
+ Stable tag: 0.3.8
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
52
 
53
  = I have a feature to suggest =
54
 
55
+ The correct place for that would be our [development site](http://trac.transposh.org "ticket system")
56
 
57
  = The interface looks messed up =
58
 
120
  5. Widget style selection
121
 
122
  == Changelog ==
123
+ = 2009/12/20 - 0.3.8 =
124
+ * Add language detection and default language settings
125
+ * Fix wrong inclusions of css and js (thanks [Kevin Hart](http://gainesvillecomputer.com/))
126
+ * Fix RSS subscription links (thanks [Kevin Hart](http://gainesvillecomputer.com/))
127
+ * Fix rel=canonical just in time for 2.9.0 (thanks [Kevin Hart](http://gainesvillecomputer.com/))
128
  = 2009/12/06 - 0.3.7 =
129
  * Fix feed parsing
130
  * Fix issue with parsing numbers before sentence breakers
transposh.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin URI: http://transposh.org/
5
  Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
6
  Author: Team Transposh
7
- Version: 0.3.7
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
@@ -73,6 +73,8 @@ class transposh_plugin {
73
  private $admin_msg;
74
  /** @var string Saved search variables*/
75
  private $search_s;
 
 
76
 
77
  /**
78
  * class constructor
@@ -112,10 +114,6 @@ class transposh_plugin {
112
  add_action('shutdown', array(&$this,'on_shutdown'));
113
  add_action('wp_print_styles', array(&$this,'add_transposh_css'));
114
  add_action('wp_print_scripts', array(&$this,'add_transposh_js'));
115
- if ($this->options->get_enable_search_translate()) {
116
- add_action('pre_get_posts', array(&$this,'pre_post_search'));
117
- add_action('posts_where_request', array(&$this,'posts_where_request'));
118
- }
119
  register_activation_hook(__FILE__, array(&$this,'plugin_activate'));
120
  register_deactivation_hook(__FILE__,array(&$this,'plugin_deactivate'));
121
  }
@@ -203,6 +201,17 @@ class transposh_plugin {
203
  $this->postpublish->get_post_phrases($_GET['post']);
204
  exit;
205
  }
 
 
 
 
 
 
 
 
 
 
 
206
  else {
207
  //set the callback for translating the page when it's done
208
  ob_start(array(&$this,"process_page"));
@@ -285,18 +294,56 @@ class transposh_plugin {
285
  function on_parse_request($wp) {
286
 
287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  // this method allows posts from the search box to maintain the language,
289
  // TODO - it has a bug of returning to original language following search, which can be resolved by removing search from widget urls, but maybe later...
290
  if (isset($wp->query_vars['s'])) {
 
 
 
 
291
  if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
292
  wp_redirect(rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false));//."&stop=y");
293
  exit;
294
  }
295
  }
296
- $this->target_language = $wp->query_vars[LANG_PARAM];
297
- if (!$this->target_language)
298
- $this->target_language = $this->options->get_default_language();
299
-
300
  if (isset($wp->query_vars[EDIT_PARAM]) && $wp->query_vars[EDIT_PARAM] && $this->is_editing_permitted()) {
301
  $this->edit_mode = true;
302
  }
@@ -436,7 +483,9 @@ class transposh_plugin {
436
  }
437
  //include the transposh.css
438
  wp_enqueue_style("transposh","{$this->transposh_plugin_url}/css/transposh.css",array(),TRANSPOSH_PLUGIN_VER);
439
- wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0');
 
 
440
 
441
  }
442
 
@@ -444,12 +493,7 @@ class transposh_plugin {
444
  * Insert references to the javascript files used in the translated version of the page.
445
  */
446
  function add_transposh_js() {
447
- //translation not allowed - no need for any js.
448
- if(!$this->is_editing_permitted() && !$this->is_auto_translate_permitted()) {
449
- return;
450
- }
451
-
452
- //not in any translation mode - no need for any js.
453
  if (!$this->edit_mode && !$this->is_auto_translate_permitted()) {
454
  return;
455
  }
@@ -467,6 +511,8 @@ class transposh_plugin {
467
  //TODO - fix (onetime var)
468
  wp_deregister_script('jquery');
469
  wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2');
 
 
470
  // jQuery pushing below might cause issues
471
  //wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2', $this->options->get_enable_footer_scripts());
472
  wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',$this->options->get_enable_footer_scripts());
@@ -475,6 +521,7 @@ class transposh_plugin {
475
  wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->options->get_msn_key(),array(),'1',$this->options->get_enable_footer_scripts());
476
  }
477
  wp_enqueue_script("transposh","{$this->transposh_plugin_url}/js/transposh.js?post_url={$this->post_url}{$edit_param}&lang={$this->target_language}&prefix=".SPAN_PREFIX,array("jquery"),TRANSPOSH_PLUGIN_VER,$this->options->get_enable_footer_scripts());
 
478
  }
479
  }
480
 
@@ -487,7 +534,7 @@ class transposh_plugin {
487
  // TODO????
488
  function is_editing_permitted() {
489
  // editing is permitted for translators only
490
- if(!$this->is_translator()) return FALSE;
491
  // and only on the non-default lang (unless strictly specified)
492
  if (!$this->options->get_enable_default_translate() && $this->options->is_default_language($this->target_language)) return false;
493
 
@@ -503,7 +550,9 @@ class transposh_plugin {
503
  function is_auto_translate_permitted() {
504
 
505
 
506
- if(!$this->options->get_enable_auto_translate()) return FALSE;
 
 
507
 
508
  return $this->options->is_editable_language($this->target_language);
509
  }
4
  Plugin URI: http://transposh.org/
5
  Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
6
  Author: Team Transposh
7
+ Version: 0.3.8
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
73
  private $admin_msg;
74
  /** @var string Saved search variables*/
75
  private $search_s;
76
+ /** @var boolean If transposh.js is on the page*/
77
+ public $js_included = false;
78
 
79
  /**
80
  * class constructor
114
  add_action('shutdown', array(&$this,'on_shutdown'));
115
  add_action('wp_print_styles', array(&$this,'add_transposh_css'));
116
  add_action('wp_print_scripts', array(&$this,'add_transposh_js'));
 
 
 
 
117
  register_activation_hook(__FILE__, array(&$this,'plugin_activate'));
118
  register_deactivation_hook(__FILE__,array(&$this,'plugin_deactivate'));
119
  }
201
  $this->postpublish->get_post_phrases($_GET['post']);
202
  exit;
203
  }
204
+ elseif (isset($_GET['tr_cookie'])) {
205
+ //$_COOKIE['TR_LNG'] = get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
206
+ setcookie('TR_LNG',get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url),time()+90*24*60*60,COOKIEPATH,COOKIE_DOMAIN);
207
+
208
+ exit;
209
+ }
210
+ elseif (isset($_GET['tr_cookie_bck'])) {
211
+ setcookie('TR_LNG',get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url),time()+90*24*60*60,COOKIEPATH,COOKIE_DOMAIN);
212
+ wp_redirect($_SERVER['HTTP_REFERER']);
213
+ exit;
214
+ }
215
  else {
216
  //set the callback for translating the page when it's done
217
  ob_start(array(&$this,"process_page"));
294
  function on_parse_request($wp) {
295
 
296
 
297
+
298
+ // first we get the target language
299
+ $this->target_language = $wp->query_vars[LANG_PARAM];
300
+ if (!$this->target_language)
301
+ $this->target_language = $this->options->get_default_language();
302
+
303
+
304
+ // we'll go into this code of redirection only if we have options that need it (and no bot is involved, for the non-cookie)
305
+ if ($this->options->get_enable_detect_language() || $this->options->get_widget_allow_set_default_language()) {
306
+ // we are starting a session if needed
307
+ if (!session_id()) session_start();
308
+ // no redirections if we already redirected in this session or we suspect cyclic redirections
309
+ if (!$_SESSION['TR_REDIRECTED'] && !($_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) {
310
+
311
+ // we redirect once per session
312
+ $_SESSION['TR_REDIRECTED'] = true;
313
+ // redirect according to stored lng cookie, and than according to detection
314
+ if (isset($_COOKIE['TR_LNG']) && $this->options->get_widget_allow_set_default_language()) {
315
+ if ($_COOKIE['TR_LNG'] != $this->target_language) {
316
+ $url = rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'],$this->edit_mode);
317
+ if ($this->options->is_default_language($_COOKIE['TR_LNG'])) $url = cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
318
+ wp_redirect($url);
319
+ exit;
320
+ }
321
+ } else {
322
+ $bestlang = prefered_language(explode(',',$this->options->get_viewable_langs()),$this->options->get_default_language());
323
+ // we won't redirect if we should not, or this is a presumable bot
324
+ if ($bestlang && $bestlang != $this->target_language && $this->options->get_enable_detect_language() && !(preg_match("#(bot|yandex|google|jeeves|spider|crawler|slurp)#si", $_SERVER['HTTP_USER_AGENT']))) {
325
+ $url = rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $bestlang,$this->edit_mode);
326
+ if ($this->options->is_default_language($bestlang)) $url = cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
327
+ wp_redirect($url);
328
+ exit;
329
+ }
330
+ }
331
+ } else {
332
+
333
+ }
334
+ }
335
  // this method allows posts from the search box to maintain the language,
336
  // TODO - it has a bug of returning to original language following search, which can be resolved by removing search from widget urls, but maybe later...
337
  if (isset($wp->query_vars['s'])) {
338
+ if ($this->options->get_enable_search_translate()) {
339
+ add_action('pre_get_posts', array(&$this,'pre_post_search'));
340
+ add_action('posts_where_request', array(&$this,'posts_where_request'));
341
+ }
342
  if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
343
  wp_redirect(rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false));//."&stop=y");
344
  exit;
345
  }
346
  }
 
 
 
 
347
  if (isset($wp->query_vars[EDIT_PARAM]) && $wp->query_vars[EDIT_PARAM] && $this->is_editing_permitted()) {
348
  $this->edit_mode = true;
349
  }
483
  }
484
  //include the transposh.css
485
  wp_enqueue_style("transposh","{$this->transposh_plugin_url}/css/transposh.css",array(),TRANSPOSH_PLUGIN_VER);
486
+ // we have to load the jquery-ui css just in some cases
487
+ if ($this->edit_mode || $this->options->get_widget_progressbar())
488
+ wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0');
489
 
490
  }
491
 
493
  * Insert references to the javascript files used in the translated version of the page.
494
  */
495
  function add_transposh_js() {
496
+ //not in any translation mode - no need for any js.
 
 
 
 
 
497
  if (!$this->edit_mode && !$this->is_auto_translate_permitted()) {
498
  return;
499
  }
511
  //TODO - fix (onetime var)
512
  wp_deregister_script('jquery');
513
  wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2');
514
+ // toying around - for later...
515
+ //wp_enqueue_script("jquery","http://code.jquery.com/jquery-1.4a2.min.js",array(),'1.4a2');
516
  // jQuery pushing below might cause issues
517
  //wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2', $this->options->get_enable_footer_scripts());
518
  wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',$this->options->get_enable_footer_scripts());
521
  wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->options->get_msn_key(),array(),'1',$this->options->get_enable_footer_scripts());
522
  }
523
  wp_enqueue_script("transposh","{$this->transposh_plugin_url}/js/transposh.js?post_url={$this->post_url}{$edit_param}&lang={$this->target_language}&prefix=".SPAN_PREFIX,array("jquery"),TRANSPOSH_PLUGIN_VER,$this->options->get_enable_footer_scripts());
524
+ $this->js_included = true;
525
  }
526
  }
527
 
534
  // TODO????
535
  function is_editing_permitted() {
536
  // editing is permitted for translators only
537
+ if(!$this->is_translator()) return false;
538
  // and only on the non-default lang (unless strictly specified)
539
  if (!$this->options->get_enable_default_translate() && $this->options->is_default_language($this->target_language)) return false;
540
 
550
  function is_auto_translate_permitted() {
551
 
552
 
553
+ if(!$this->options->get_enable_auto_translate()) return false;
554
+ // auto translate is not enabled for default target language when enable default is disabled
555
+ if (!$this->options->get_enable_default_translate() && $this->options->is_default_language($this->target_language)) return false;
556
 
557
  return $this->options->is_editable_language($this->target_language);
558
  }
transposh_admin.php CHANGED
@@ -35,7 +35,7 @@ class transposh_plugin_admin {
35
  $this->transposh = &$transposh;
36
  // FIX (probably always happens?)
37
  if ($this->transposh->options->get_widget_css_flags())
38
- wp_enqueue_style("transposh-flags",plugins_url('', __FILE__)."/css/transposh_flags.css",array(),TRANSPOSH_PLUGIN_VER);
39
  //add filter for WordPress 2.8 changed backend box system !
40
  add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2);
41
  //add some help
@@ -107,6 +107,7 @@ class transposh_plugin_admin {
107
 
108
  $this->transposh->options->set_enable_footer_scripts($_POST[ENABLE_FOOTER_SCRIPTS]);
109
  $this->transposh->options->set_alternate_post($_POST[ALTERNATE_POST]);
 
110
  $this->transposh->options->set_enable_auto_translate($_POST[ENABLE_AUTO_TRANSLATE]);
111
  $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]);
112
  $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]);
@@ -455,6 +456,14 @@ class transposh_plugin_admin {
455
  echo '</select> ';
456
  echo 'Change this option only if changes fail to get saved on the database';
457
 
 
 
 
 
 
 
 
 
458
  /* WIP echo '<h4>Show original language first</h4>';*/
459
  /*foreach($languages as $code => $lang) {
460
  list ($language,$flag,$autot) = explode (",",$lang);
35
  $this->transposh = &$transposh;
36
  // FIX (probably always happens?)
37
  if ($this->transposh->options->get_widget_css_flags())
38
+ wp_enqueue_style("transposh_flags",plugins_url('', __FILE__)."/css/transposh_flags.css",array(),TRANSPOSH_PLUGIN_VER);
39
  //add filter for WordPress 2.8 changed backend box system !
40
  add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2);
41
  //add some help
107
 
108
  $this->transposh->options->set_enable_footer_scripts($_POST[ENABLE_FOOTER_SCRIPTS]);
109
  $this->transposh->options->set_alternate_post($_POST[ALTERNATE_POST]);
110
+ $this->transposh->options->set_enable_detect_language($_POST[ENABLE_DETECT_LANG_AND_REDIRECT]);
111
  $this->transposh->options->set_enable_auto_translate($_POST[ENABLE_AUTO_TRANSLATE]);
112
  $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]);
113
  $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]);
456
  echo '</select> ';
457
  echo 'Change this option only if changes fail to get saved on the database';
458
 
459
+ /**
460
+ * Insert the option to enable/disable language auto-detection
461
+ * @since 0.3.8 */
462
+ echo '<h4>Auto detect language for users</h4>';
463
+ echo '<input type="checkbox" value="1" name="'.ENABLE_DETECT_LANG_AND_REDIRECT.'" '. $this->checked($this->transposh->options->get_enable_detect_language()) . '/> '.
464
+ 'This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. '.
465
+ 'This will redirect the first page accessed in the session to the same page with the detected language.';
466
+
467
  /* WIP echo '<h4>Show original language first</h4>';*/
468
  /*foreach($languages as $code => $lang) {
469
  list ($language,$flag,$autot) = explode (",",$lang);
transposh_db.php CHANGED
@@ -301,6 +301,8 @@ class transposh_database {
301
  }
302
  }
303
 
 
 
304
  // perform insertion to the database, with one query :)
305
  $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)
306
  VALUES $values";
301
  }
302
  }
303
 
304
+ // avoid empty work
305
+ if (!$values) return;
306
  // perform insertion to the database, with one query :)
307
  $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)
308
  VALUES $values";
transposh_options.php CHANGED
@@ -14,7 +14,7 @@
14
  * You should have received a copy of the GNU General Public License
15
  * along with this program; if not, write to the Free Software
16
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
- */
18
  // OLD Options - To be removed
19
  //Option defining whether anonymous translation is allowed.
20
  define("OLD_ANONYMOUS_TRANSLATION", "transposh_allow_anonymous_translation");
@@ -64,8 +64,10 @@ define("ENABLE_SEARCH_TRANSLATE", "enable_search_translate");
64
  define("ENABLE_PERMALINKS", "enable_permalinks");
65
  //Option to enable/disable footer scripts (2.8 and up)
66
  define("ENABLE_FOOTER_SCRIPTS", "enable_footer_scripts");
67
- //Option to enable/disable footer scripts (2.8 and up)
68
  define("ALTERNATE_POST", "alternate_post_method");
 
 
69
  //Option defining the default language
70
  define("DEFAULT_LANG", "default_language");
71
  //Option defining transposh widget appearance
@@ -76,6 +78,8 @@ define("WIDGET_PROGRESSBAR", "widget_progressbar");
76
  define("WIDGET_CSS_FLAGS", "widget_css_flags");
77
  //Wrap widget elements in an unordered list per #63 @since 0.3.7
78
  define("WIDGET_IN_LIST", "widget_in_list");
 
 
79
 
80
 
81
  class transposh_plugin_options {
@@ -162,6 +166,10 @@ class transposh_plugin_options {
162
  return $this->options[WIDGET_IN_LIST];
163
  }
164
 
 
 
 
 
165
  function get_enable_permalinks() {
166
  return $this->options[ENABLE_PERMALINKS];
167
  }
@@ -174,6 +182,10 @@ class transposh_plugin_options {
174
  return $this->options[ALTERNATE_POST];
175
  }
176
 
 
 
 
 
177
  function get_enable_msn_translate() {
178
  return $this->options[ENABLE_MSN_TRANSLATE]; // FIX
179
  }
@@ -257,6 +269,11 @@ class transposh_plugin_options {
257
  $this->set_value($val, $this->options[WIDGET_IN_LIST]);
258
  }
259
 
 
 
 
 
 
260
  function set_enable_permalinks($val) {
261
  $val = ($val) ? 1 : 0;
262
  $this->set_value($val, $this->options[ENABLE_PERMALINKS]);
@@ -266,6 +283,11 @@ class transposh_plugin_options {
266
  $this->set_value($val,$this->options[ALTERNATE_POST]);
267
  }
268
 
 
 
 
 
 
269
  function set_enable_footer_scripts($val) {
270
  $val = ($val) ? 1 : 0;
271
  $this->set_value($val, $this->options[ENABLE_FOOTER_SCRIPTS]);
14
  * You should have received a copy of the GNU General Public License
15
  * along with this program; if not, write to the Free Software
16
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
  // OLD Options - To be removed
19
  //Option defining whether anonymous translation is allowed.
20
  define("OLD_ANONYMOUS_TRANSLATION", "transposh_allow_anonymous_translation");
64
  define("ENABLE_PERMALINKS", "enable_permalinks");
65
  //Option to enable/disable footer scripts (2.8 and up)
66
  define("ENABLE_FOOTER_SCRIPTS", "enable_footer_scripts");
67
+ //Option to enable/disable footer scripts (2.8 and up) -- TODO should go away
68
  define("ALTERNATE_POST", "alternate_post_method");
69
+ //Option to enable detect and redirect language @since 0.3.8
70
+ define("ENABLE_DETECT_LANG_AND_REDIRECT", "enable_detect_redirect");
71
  //Option defining the default language
72
  define("DEFAULT_LANG", "default_language");
73
  //Option defining transposh widget appearance
78
  define("WIDGET_CSS_FLAGS", "widget_css_flags");
79
  //Wrap widget elements in an unordered list per #63 @since 0.3.7
80
  define("WIDGET_IN_LIST", "widget_in_list");
81
+ //Allows user to set his default language per #63 @since 0.3.8
82
+ define("WIDGET_ALLOW_SET_DEFLANG", "widget_allow_set_deflang");
83
 
84
 
85
  class transposh_plugin_options {
166
  return $this->options[WIDGET_IN_LIST];
167
  }
168
 
169
+ function get_widget_allow_set_default_language() {
170
+ return $this->options[WIDGET_ALLOW_SET_DEFLANG];
171
+ }
172
+
173
  function get_enable_permalinks() {
174
  return $this->options[ENABLE_PERMALINKS];
175
  }
182
  return $this->options[ALTERNATE_POST];
183
  }
184
 
185
+ function get_enable_detect_language() {
186
+ return $this->options[ENABLE_DETECT_LANG_AND_REDIRECT];
187
+ }
188
+
189
  function get_enable_msn_translate() {
190
  return $this->options[ENABLE_MSN_TRANSLATE]; // FIX
191
  }
269
  $this->set_value($val, $this->options[WIDGET_IN_LIST]);
270
  }
271
 
272
+ function set_widget_allow_set_default_language($val) {
273
+ $val = ($val) ? 1 : 0;
274
+ $this->set_value($val, $this->options[WIDGET_ALLOW_SET_DEFLANG]);
275
+ }
276
+
277
  function set_enable_permalinks($val) {
278
  $val = ($val) ? 1 : 0;
279
  $this->set_value($val, $this->options[ENABLE_PERMALINKS]);
283
  $this->set_value($val,$this->options[ALTERNATE_POST]);
284
  }
285
 
286
+ function set_enable_detect_language($val) {
287
+ $val = ($val) ? 1 : 0;
288
+ $this->set_value($val,$this->options[ENABLE_DETECT_LANG_AND_REDIRECT]);
289
+ }
290
+
291
  function set_enable_footer_scripts($val) {
292
  $val = ($val) ? 1 : 0;
293
  $this->set_value($val, $this->options[ENABLE_FOOTER_SCRIPTS]);
transposh_widget.php CHANGED
@@ -121,13 +121,6 @@ class transposh_plugin_widget {
121
  $page_url = $_SERVER["REQUEST_URI"];
122
 
123
 
124
- //$options = get_option(WIDGET_TRANSPOSH);
125
- $viewable_langs = $this->transposh->options->get_viewable_langs();
126
- $editable_langs = $this->transposh->options->get_editable_langs();
127
-
128
-
129
- $is_translator = $this->transposh->is_translator();
130
-
131
  $is_showing_languages = FALSE;
132
  //TODO: improve this shortening
133
  $plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
@@ -149,10 +142,12 @@ class transposh_plugin_widget {
149
  list($language,$flag) = explode (",",$lang2);
150
 
151
  //Only show languages which are viewable or (editable and the user is a translator)
152
- if(strpos($viewable_langs, $code) !== FALSE || $this->transposh->options->is_editable_language($code) || ($this->transposh->options->get_default_language() == $code)) {
 
 
153
 
154
  $page_url = rewrite_url_lang_param($clean_page_url,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $code, $this->transposh->edit_mode);
155
- if ($this->transposh->options->get_default_language() == $code) {
156
  $page_url = $clean_page_url;
157
  }
158
 
@@ -188,7 +183,9 @@ class transposh_plugin_widget {
188
  list($language,$flag) = explode (",",$lang2);
189
 
190
  //Only show languages which are viewable or (editable and the user is a translator)
191
- if(strpos($viewable_langs, $code) !== FALSE || $this->transposh->options->is_editable_language($code) || ($this->transposh->options->get_default_language() == $code)) {
 
 
192
  $is_selected = ($this->transposh->target_language == $code ? "selected=\"selected\"" : "" );
193
  echo "<option value=\"$code\" $is_selected>" . $language . "</option>";
194
  $is_showing_languages = TRUE;
@@ -200,6 +197,15 @@ class transposh_plugin_widget {
200
 
201
  //at least one language showing - add the edit box if applicable
202
  if($is_showing_languages) {
 
 
 
 
 
 
 
 
 
203
  //Add the edit checkbox only for translators on languages marked as editable
204
  if($this->transposh->is_editing_permitted()) {
205
  echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
@@ -214,8 +220,8 @@ class transposh_plugin_widget {
214
  echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
215
  }
216
 
217
- if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
218
  echo "</form>";
 
219
  //TODO: maybe... echo "<button onClick=\"do_auto_translate();\">translate all</button>";
220
  if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
221
  // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
@@ -238,6 +244,7 @@ class transposh_plugin_widget {
238
  $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]);
239
  $this->transposh->options->set_widget_css_flags($_POST[WIDGET_CSS_FLAGS]);
240
  $this->transposh->options->set_widget_in_list($_POST[WIDGET_IN_LIST]);
 
241
  if ($save)
242
  $this->transposh->options->update_options();
243
  // Avoid coming here twice...
@@ -263,6 +270,8 @@ class transposh_plugin_widget {
263
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Show progress bar when a client triggers automatic translation">Show progress bar</span><br/>'.
264
  '<input type="checkbox" id="'.WIDGET_CSS_FLAGS.'" name="'.WIDGET_CSS_FLAGS.'"'.($this->transposh->options->get_widget_css_flags() ? ' checked="checked"' : '').'/>'.
265
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Use a single sprite with all flags, makes pages load faster. Currently not suitable if you made changes to the flags.">Use CSS flags</span><br/>'.
 
 
266
  '<input type="checkbox" id="'.WIDGET_IN_LIST.'" name="'.WIDGET_IN_LIST.'"'.($this->transposh->options->get_widget_in_list() ? ' checked="checked"' : '').'/>'.
267
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Wraps generated widget code with UL helps with some CSSs.">Wrap widget with an unordered list (UL)</span>'.
268
  '</p>'.
121
  $page_url = $_SERVER["REQUEST_URI"];
122
 
123
 
 
 
 
 
 
 
 
124
  $is_showing_languages = FALSE;
125
  //TODO: improve this shortening
126
  $plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
142
  list($language,$flag) = explode (",",$lang2);
143
 
144
  //Only show languages which are viewable or (editable and the user is a translator)
145
+ if($this->transposh->options->is_viewable_language($code) ||
146
+ ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
147
+ ($this->transposh->options->is_default_language($code))) {
148
 
149
  $page_url = rewrite_url_lang_param($clean_page_url,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $code, $this->transposh->edit_mode);
150
+ if ($this->transposh->options->is_default_language($code)) {
151
  $page_url = $clean_page_url;
152
  }
153
 
183
  list($language,$flag) = explode (",",$lang2);
184
 
185
  //Only show languages which are viewable or (editable and the user is a translator)
186
+ if($this->transposh->options->is_viewable_language($code) ||
187
+ ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
188
+ ($this->transposh->options->is_default_language($code))) {
189
  $is_selected = ($this->transposh->target_language == $code ? "selected=\"selected\"" : "" );
190
  echo "<option value=\"$code\" $is_selected>" . $language . "</option>";
191
  $is_showing_languages = TRUE;
197
 
198
  //at least one language showing - add the edit box if applicable
199
  if($is_showing_languages) {
200
+ if ($this->transposh->options->get_widget_allow_set_default_language()) {
201
+ 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))) {
202
+ if ($this->transposh->js_included) {
203
+ echo '<a href="#" id="'.SPAN_PREFIX.'setdeflang" onClick="return false;">Set as default language</a><br/>';
204
+ } else {
205
+ echo '<a href="'.$this->transposh->home_url.'?tr_cookie_bck">Set as default language</a><br/>';
206
+ }
207
+ }
208
+ }
209
  //Add the edit checkbox only for translators on languages marked as editable
210
  if($this->transposh->is_editing_permitted()) {
211
  echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
220
  echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
221
  }
222
 
 
223
  echo "</form>";
224
+ if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
225
  //TODO: maybe... echo "<button onClick=\"do_auto_translate();\">translate all</button>";
226
  if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
227
  // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
244
  $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]);
245
  $this->transposh->options->set_widget_css_flags($_POST[WIDGET_CSS_FLAGS]);
246
  $this->transposh->options->set_widget_in_list($_POST[WIDGET_IN_LIST]);
247
+ $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]);
248
  if ($save)
249
  $this->transposh->options->update_options();
250
  // Avoid coming here twice...
270
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Show progress bar when a client triggers automatic translation">Show progress bar</span><br/>'.
271
  '<input type="checkbox" id="'.WIDGET_CSS_FLAGS.'" name="'.WIDGET_CSS_FLAGS.'"'.($this->transposh->options->get_widget_css_flags() ? ' checked="checked"' : '').'/>'.
272
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Use a single sprite with all flags, makes pages load faster. Currently not suitable if you made changes to the flags.">Use CSS flags</span><br/>'.
273
+ '<input type="checkbox" id="'.WIDGET_ALLOW_SET_DEFLANG.'" name="'.WIDGET_ALLOW_SET_DEFLANG.'"'.($this->transposh->options->get_widget_allow_set_default_language() ? ' checked="checked"' : '').'/>'.
274
+ '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Widget will allow setting this language as user default.">Allow user to set current language as default</span><br/>'.
275
  '<input type="checkbox" id="'.WIDGET_IN_LIST.'" name="'.WIDGET_IN_LIST.'"'.($this->transposh->options->get_widget_in_list() ? ' checked="checked"' : '').'/>'.
276
  '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Wraps generated widget code with UL helps with some CSSs.">Wrap widget with an unordered list (UL)</span>'.
277
  '</p>'.