支持语言


REST API

Method
translate POST /language/translate/v2 (Translates input text, returning translated text.)
detect POST /language/translate/v2/detect (Detects the language of text within a request.)

KEY

API_KEY =

实例

translate翻译

使用 curl 向 https://translation.googleapi... 端点发出请求。该 curl 命令中包含待翻译文本 (q)、源语言 (source) 以及目标语言 (target) 对应的 JSON。


$url = 'https://translation.googleapis.com/language/translate/v2?key=API_KEY';
$headers = array();
$headers[]='Content-Type: application/json';
$data = [
'q'=>'我最喜欢的城市是堪培拉',
'source'=>'zh-CN',
'target'=>'en',
'format'=>'text',
'model'=>''
];
$data = json_encode($data);
$res = curl($url,'post',$data,$headers);
return $res;

特殊参数 model
The translation model. Can be either base to use the Phrase-Based Machine Translation (PBMT) model, or nmt to use the Neural Machine Translation (NMT) model. If omitted, then nmt is used.
If the model is nmt, and the requested language translation pair is not supported for the NMT model, then the request is translated using the base model.

返回值


"{
"data": {
"translations": [
{
"translatedText": "My favorite city is Canberra"
}
]
}
}

detect检测语言

检测请求中的语言,并返回语言代码


$url = 'https://translation.googleapis.com/language/translate/v2/detect?key=API_KEY';
$headers = array();
$headers[]='Content-Type: application/json';
$data = [
'q'=>'我最喜欢的城市是堪培拉'
];
$data = json_encode($data);
$res = curl($url,'post',$data,$headers);
return $res;

返回值


"{
"data": {
"detections": [
[
{
"confidence": 1,
"isReliable": false,
"language": "zh-CN"
}
]
]
}
}

原文地址:https://segmentfault.com/a/1190000016278417

最新文章

  1. robotframework接口测试初探2
  2. R语言实战读书笔记(二)创建数据集
  3. Write operations are not allowed in read-only mode错误
  4. C++中String类的实现
  5. MongoDB - Installing MongoDB on Linux
  6. HDU-4607 Park Visit bfs | DP | dfs
  7. Spring HibernateTemplate的使用
  8. python基础学习笔记4--抽象
  9. how tomcat works 读书笔记九 Session管理
  10. table新增空白行到首行
  11. mock打桩之EasyMock
  12. 目标检测(一) R-CNN
  13. navicat连接sqlserver数据库提示:未发现数据源名称并且未指定默认驱动程序
  14. Linux中计划任务、周期性任务设置
  15. asp.netmvc 三层搭建一个完整的项目
  16. Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境
  17. Javascript面向对象二
  18. C++ 中的关于输出的设置于
  19. js获取网页上选中的部分,包含html代码
  20. git远程易错点

热门文章

  1. HDU 2295
  2. HDU 5175
  3. [Javascript Crocks] Safely Access Object Properties with `prop`
  4. Struts2 动态结果集
  5. ajax传对象或者数组到后端
  6. 剖析Mysql的InnoDB索引
  7. luogu2761 软件补丁问题 状态压缩最短路径
  8. hdu 1085(普通母函数)
  9. axis2调用webservice教训
  10. Node.js:RESTful API