在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以买到DeepL的Pro账号。
function DeepL($value,$auth_key,$target){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.deepl.com/v1/translate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"auth_key=".$auth_key."&text=".$value."&target_lang=".$target);
//这玩意很蛋疼,一定要把HTTPS检测关了。不然无法运行的
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//这玩意很蛋疼,一定要把HTTPS检测关了。不然无法运行的
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$translatedWords = json_decode($result, true); // Decode the word
$result = $translatedWords['translations'][0]['text']; // Search the word
return $result;
}
$vale = '需要翻译的文本';
$auth_key = ''; //这个是自己要有DeepLPro账号才能生成,直接后台那个key就是,贴进来就行
echo DeepL($value,$auth_key,"EN");
The End

大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)