Using Google Translate through YQL with cURL and parsing the results with XMLReader. View a demo here.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>YQL XMLReader Google Translate</title>
</head>
<body>
<?php
$poem = <<<EOT
A Dream Within A Dream by Edgar Allan Poe<br /><br />
Take this kiss upon the brow!<br />
And, in parting from you now,<br />
Thus much let me avow--<br />
You are not wrong, who deem<br />
That my days have been a dream;<br />
Yet if hope has flown away<br />
In a night, or in a day,<br />
In a vision, or in none,<br />
Is it therefore the less gone?<br />
All that we see or seem<br />
Is but a dream within a dream.<br /><br />
I stand amid the roar<br />
Of a surf-tormented shore,<br />
And I hold within my hand<br />
Grains of the golden sand--<br />
How few! yet how they creep<br />
Through my fingers to the deep,<br />
While I weep--while I weep!<br />
O God! can I not grasp<br />
Them with a tighter clasp?<br />
O God! can I not save<br />
One from the pitiless wave?<br />
Is all that we see or seem<br />
But a dream within a dream?
EOT;
echo "<p>$poem</p>\n";
echo "<hr />\n";
$query = 'select * from google.translate where q="'.$poem.'" and target="fr"';
$query = 'http://query.yahooapis.com/v1/public/yql?q='.urlencode($query).'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
// Make call with cURL
$session = curl_init($query);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($session);
$reader = new XMLReader();
$reader->xml($xml);
while ($reader->read()) {
if ($reader->name == '#text') {
$text = $reader->value;
echo "<p>$text</p>\n";
}
}
?>
</body>
</html>