I use below PHP code in Laravel to translate one sentence or paragraph from one input field:
$apiKey = env('GOOGLE_TRANSLATOR_API');
$url = env('GOOGLE_TRANSLATOR_LINK') . $apiKey . '&q=' . rawurlencode($name) . '&target='.$language;
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
return $responseDecoded['data']['translations'][0]['translatedText'];
and it works perfectly fine.
But now I have two input fields (name and description) and I want to translate both of those fields using one API call and show the results individually.
EDIT
I have tried to use array in the API request as below:
$apiKey = env('GOOGLE_TRANSLATOR_API');
$url = env('GOOGLE_TRANSLATOR_LINK') . $apiKey . '&q=' . array('sentence one', 'sentence two) . '&target='.$language;
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
return $responseDecoded['data']['translations'][0]['translatedText'];
But I get Array to string conversion error.