From 5492751a2fdf9ab79ebfd5f3d2a87f2f3b70311f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Feb 2012 17:11:29 +0100 Subject: [PATCH] New: autotranslator works with new google v2 translate --- dev/translation/autotranslator.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dev/translation/autotranslator.class.php b/dev/translation/autotranslator.class.php index 944b6556920..b6fbe202ba1 100644 --- a/dev/translation/autotranslator.class.php +++ b/dev/translation/autotranslator.class.php @@ -301,7 +301,7 @@ class autoTranslator // Example: https://www.googleapis.com/language/translate/v2?key=APIKEY&q=Setup%20area&source=en_US&target=fr_FR // Send request - print "Url to translate: ".$url."\n"; + //print "Url to translate: ".$url."\n"; if (! function_exists("curl_init")) { @@ -315,18 +315,19 @@ class autoTranslator curl_setopt($ch, CURLOPT_REFERER, "Mozilla"); $body = curl_exec($ch); curl_close($ch); - sleep(6); // This is to avoid to overload server. Best value is 6. + //sleep(1); // This is to avoid to overload server. // now, process the JSON string $json = json_decode($body, true); - if ($json['responseStatus'] != 200) + if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200) + || count($json['data']['translations']) == 0) { - print "Error: ".$json['responseStatus']." ".$url."\n"; + print "Error: ".$json['responseStatus']." ".$url."\n"; return false; } - $rep=$json['responseData']['translatedText']; + $rep=$json['data']['translations'][0]['translatedText']; $rep=preg_replace('/SSSSS/i','%s',$rep); $rep=preg_replace('/NNNNN/i','\n\n',$rep); $rep=preg_replace('/'/i','\'',$rep);