彩云小译 API
五分钟学会彩云小译 API
五分钟学会彩云小译 API
彩云小译 API 可以用来把信息翻译到指定的语言,我们可以支持文本、网页、PDF/Word 文档、语音、视频等多种形式。
您可以使用它来构建你的应用程序、网站、工具或任何需要多语言支持的解决方案。例如:彩云小译 API 是维基百科自动翻译的技术提供者,也为钉钉、石墨文档、财新传媒等一线机构和众多开发者提供技术支持。
维基百科内容翻译 | 石墨文档翻译 |
---|---|
![]() | ![]() |
3975l6lr5pcbvidl6jl2
作为测试 Token,我们不保证该 Token 的可用性,所以如果要持续使用,还请申请正式 Token。POST https://api.interpreter.caiyunai.com/v1/translator
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
source | string[] 或 string | 是 | 待翻译的文本 |
trans_type | string | 是 | 翻译方向,支持的值见下方支持的语言 |
detect | boolean | 否 | 是否检测源语言,如果 trans_type 为 auto2xx 则必须为 true |
media | string | 否 | 媒体类型 |
request_id | string | 否 | 请求 ID |
curl -s -X POST https://api.interpreter.caiyunai.com/v1/translator \
-H "Content-Type: application/json" \
-H "X-Authorization: token $TOKEN" \
-d '{
"source": [
"Lingocloud is the best translation service."
],
"trans_type": "auto2zh",
"detect": true,
"media": "text",
"request_id": "demo"
}'
import json
import requests
def translate(source, direction):
url = "https://api.interpreter.caiyunai.com/v1/translator"
# WARNING, this token is a test token for new developers,
# and it should be replaced by your token
token = "YOUR_TOKEN"
payload = {
"source": source,
"trans_type": direction,
"request_id": "demo",
"detect": direction.startswith("auto"),
}
headers = {
"content-type": "application/json",
"x-authorization": "token " + token,
}
response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
return json.loads(response.text)["target"]
source = ["Lingocloud is the best translation service.", "彩云小译は最高の翻訳サービスです"]
target = translate(source, "auto2zh")
print(target)
# ['小译翻译是最好的翻译服务。', '彩云小译是最好的翻译服务']
目前支持的语言和翻译方向如下表所示
From-to | 中文 zh | 繁体中文 zh-Hant | 英语 en | 日文 ja | 韩语 ko |
---|---|---|---|---|---|
中文 zh | - | zh2zh-Hant | zh2en | zh2ja | zh2ko |
繁体中文 zh-Hant | zh-Hant2zh | - | zh-Hant2en | zh-Hant2ja | zh-Hant2ko |
英语 en | en2zh | en2zh-Hant | - | - | |
日文 ja | ja2zh | ja2zh-Hant | - | - | |
韩语 ko | ko2zh | ko2zh-Hant | - | - | |
德语 de | de2zh | de2zh-Hant | - | - | |
西班牙语 es | es2zh | es2zh-Hant | - | - | |
法语 fr | fr2zh | fr2zh-Hant | - | - | |
意大利语 it | it2zh | it2zh-Hant | - | - | |
葡萄牙语 pt | pt2zh | pt2zh-Hant | - | - | |
俄语 ru | ru2zh | ru2zh-Hant | - | - | |
土耳其语 tr | tr2zh | tr2zh-Hant | - | - | |
越南语 vi | vi2zh | vi2zh-Hant | - | - |
使用 auto2xx
可以自动识别源语言的语种。目前 Web 已支持多种语言,API 开放更多语言请邮件联系。
platform@caiyunapp.com
联系!