Jump to content

how to translate a php script to another language ?


samoi

Recommended Posts

May I ask why you first link to the API, but don't use it anyway?

 

You can just call the API directly instead of parsing the output of the translating frontend...

 

function translate($textSource, $langSource, $langTarget)
{
$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource) . '&langpair=' . urlencode($langSource . '|' . $langTarget),
	CURLOPT_RETURNTRANSFER => true
));

$ret = json_decode(curl_exec($ch), true);
curl_close($ch);

if ($ret['responseStatus'] != '200') {
	throw Exception('Translation failed.');
}

return $ret['responseData']['translatedText'];
}

echo translate('ciao', 'it', 'en');

google seems like his best bet

 

the output will not be perfect in arabic but I am sure he could edit it so it makes sense.

 

http://translate.google.com/

 

I translated a site from english to chinese using google and it was a far from perfect translation lol

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.