Archive for the 'Content Generation' Category

15.05.2007

The Kaptain wrote this little script to allow him to translate some pages on the fly and thought you might enjoy it as well. You will need a copy of the Snoopy class in order for this to work.

If you make any additions or changes to the code let the Kaptain know and he will post your new version and tell the world how great you are.

1
2
3
4
5
6
7
8
9
10
11
12
13
include("Snoopy.class.php");
function translate($content,$inlang,$outlang){
        $snoopy = new Snoopy;
        //http://google.com/translate_t?hl=en&ie=UTF8&text=eat+pie&langpair=en%7Cit
	$trans_url = "http://google.com/translate_t?hl=en&ie=UTF8&text=".urlencode($content)."&langpair=".$inlang."|".$outlang;
	$page = $snoopy->fetch($trans_url);
	$page = $snoopy->results;
 
	//parse out the data we need
	preg_match("/<div\s+id=result_box\s+dir=ltr>(.*?)<\/div>/i",$page,$match);	
 
	return $match[1];
}

Happy Translating!

Clicky Web Analytics
taky