"", "language_pair" => "");
public $out = "";
public function __construct($from = "en", $to = "cs")
{
$this->from = $from;
$this->to = $to;
}
function translate($text)
{
$this->out = "";
$this->opts["text"] = $text;
$this->opts["language_pair"] = $this->from . "|" . $this->to;
$google_translator_url = "http://translate.google.com/translate_t?langpair=".urlencode($this->opts["language_pair"])."&";
$google_translator_data .= "text=".urlencode($this->opts["text"]);
$gphtml = $this->postPage(array("url" => $google_translator_url, "data" => $google_translator_data));
$out = substr($gphtml, strpos($gphtml, "
"));
$out = substr($out, 29);
$out = substr($out, 0, strpos($out, "
"));
$this->out = utf8_encode($out);
return $this->out;
}
function postPage($opts)
{
$html = "";
if($opts["url"] != "" && $opts["data"] != "")
{
$ch = curl_init($opts["url"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $opts["data"]);
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
/*
$g = new GoogleTranslate();
echo $g->translate("Good day");
*/
?>