我正在尝试将英语翻译成阿拉伯语。但它只翻译一个字。 单词只会被翻译。 这是我的代码:
$curl = curl_init();curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.googleapis.com/language/translate/v2?key=".$api_key."&q=".$text."&source=".$source_language."&target=".$target_language, CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
),
)); $response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$arr = json_decode($response,true);
print_r($arr['data']['translations']);
echo $response;exit;
}