PHP调用谷歌翻译
- 启用 Cloud Translation API。
https://cloud.google.com/translate/docs/setup?hl=zh-cn
- 创建秘钥
https://console.cloud.google.com/apis/credentials?project=redcaptask
秘钥限制,默认 无,不要添加限制,否则调用翻译会报没有权限
3.翻译
翻译文档:https://cloud.google.com/php/docs/reference/cloud-translate/latest
protected $key = 'AIza*********************fW3uVm0kuCbLM0g';
/**
* Notes:单个翻译
* Interface:translate
* Author: 。。。
* CreatTime: 2023/8/16 14:46
* @param string $content 要翻译的内容
* @param string $to_lang 目标语言
* @return \think\response\Json
* @throws \Google\Cloud\Core\Exception\GoogleException
* @throws \Google\Cloud\Core\Exception\ServiceException
*/
public function translate($content = '',$to_lang