Hello wordpress, hello everybody!
I have a problem, i have a function to translate my content from french into italian language.
But i want, when i create a new post in french language to translate it automatically into italian language and after that to add it into database.
There is the function
function mycurl($url,$post){
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_POST, 4);
$file_contents = curl_exec($ch);
curl_close($ch);
$lines = array();
$lines = explode("\n", $file_contents);
$results = $lines ;
$results = implode("", $results);
return $results;
}
function my_translator($post_content){
$url = "http://translate.google.com/translate_t";
$content=urlencode($post_content);
$data="?hl=en|fr&text=".$content;
$results= mycurl($url,$data);
preg_match_all('/<textarea name=utrans wrap=SOFT dir="ltr" rows=5 id=suggestion>(.*?)\<\/textarea>/s', $results, $matches);
$content=urlencode($matches[1][0]);
return $matches[1][0];
}
If somebody can help me, i will appreciate this!
Thank you!
weblaffin