台州温岭做网站请找我们 (专业建站 | 诚信服务) 13958630945 在线客服 联系技术

佳源设计|台州网站建设|佳源网页设计

网站当前位置: 首页>>做网站步骤>>PHP调用Google Translate API接口
建站流程
 
建站知识
 
网站建站疑难
 
网站设计_图象处理
 
网站设计_Css样式
 
网站建设_Flash疑难
 
手机网站建设
 
 建站知识搜索
 

台州网站建设
 
网站优化
 
提交疑问
 做网站步骤 > PHP调用Google Translate API接口

PHP调用Google Translate API接口

1839次浏览
2021-06-18
转载自:https://www.cnblogs.com/66w66/p/13723424.html

官方地址: 
准备工作
设置 Cloud Console 项目。
设置项目 
点击即可执行以下操作:
创建或选择项目。
为该项目启用 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
上一篇 >>IIS服务器备份导入与导出
下一篇 >>Leaflet示例