[ create a new paste ] login | about

Link: http://codepad.org/IrP8opQM    [ raw code | fork ]

racerxdl - PHP, pasted on Sep 7:
<?
function translate($msg, $from="", $to="pt-br") {
	$tUrl = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($msg)."&langpair=".$from."|".$to;
	$curl = curl_init($tUrl);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
	curl_setopt($curl, CURLOPT_HEADER, 0); 
	curl_setopt($curl, CURLOPT_POST, true); 
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile"); 
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile"); # SAME cookiefile 
    $output = curl_exec($curl);       
    curl_close($curl);
	$rt = json_decode($output, TRUE);
	return $rt;
}
header("Content-Type: text/plain; charset=UTF-8");
$mensagem = translate($_REQUEST["mensagem"]);
$from = $mensagem["responseData"]["detectedSourceLanguage"];
if($mensagem["responseStatus"] == 400)
	$mensagem = $_REQUEST["mensagem"];
else
	$mensagem = utf8_encode($mensagem["responseData"]["translatedText"]);


$x = strip_tags(file_get_contents("http://www.ed.conpet.gov.br/mod_perl/bot_gateway.cgi?server=0.0.0.0:8085&charset=utf-8&pure=1&js=0&msg=".$mensagem));

if($mensagem == $_REQUEST["mensagem"])
	echo $x;
else{
	$resp = translate($x,"",$from);
	echo($resp["responseData"]["translatedText"]);
}
?>


Create a new paste based on this one


Comments: