转载自:https://www.cnblogs.com/66w66/p/13723424.html
官方地址: https://cloud.google.com/translate/#section-1 准备工作 设置 Cloud Console 项目。 设置项目 https://cloud.google.com/translate/docs/basic/setup-basic 点击即可执行以下操作: 创建或选择项目。 为该项目启用 Cloud Translation API。 创建服务帐号。 下载 JSON 格式的私钥。 您可以随时在 Cloud Console 中查看和管理这些资源。https://console.cloud.google.com 1.创建项目
2.您需要为此项目提供一个计费帐户,然后才能激活该服务。 访问API控制台以配置结算帐户,然后返回此处继续操作。
3.下载秘钥
4.为项目开启API功能
5.搜索需要开启的API类型
6.创建API Key
服务器中先安装composer
composer require google/cloud-translate
记得安装后的文件夹,后续脚本需要用到。 使用: PHP文件中引用翻译库的autoload路径。 require_once ('vendor/autoload.php');
use Google\Cloud\Translate\TranslateClient;
调用示例 $translate = new TranslateClient([
'key' => '这里写谷歌后台的APIKEY'
]);
$result = $translate->translate('<p>Get the languages <img src="https://www.baidu.com/img/flexible/logo/pc/result.png"/>supported for translation</p> specifically for your target language.',
[
'source' => 'en',//默认EN,不设置自动检测原始语言
'target' => 'zh-CN'
]);
echo $result['text'] . "\n";
页面所在本站地址: http://www.52-life.net/N_Translate_API.htm |