According to google and Sitepoint, there are possibilities to translate multiple text strings in one request. However when I tried to translate multiple strings, it resulted in replacing the first string by the last one.
$handle = curl_init();
if (FALSE === $handle)
throw new Exception('failed to initialize');
curl_setopt($handle, CURLOPT_URL,'https://www.googleapis.com/language/translate/v2');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('key'=> $apiKey, 'q' => $heading, 'q' => $content, 'source' => $sl, 'target' => $hl));
curl_setopt($handle,CURLOPT_HTTPHEADER,array('X-HTTP-Method-Override: GET'));
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
$responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if($responseCode != 200) {
header("HTTP/1.0 404 Not Found");
include_once("ErrorDocument/404.html");
exit();
}else{
$heading = $responseDecoded['data']['translations'][0]['translatedText'];
$content = $responseDecoded['data']['translations'][1]['translatedText'];
}
Any ideas?