消息翻译

功能描述

文本消息翻译目前仅支持手动调接口翻译文本消息内容,图片、视频、文件、语音、自定义消息等非文本内容均不支持翻译。
说明:
文本消息翻译功能仅对专业版 Plus 和企业版客户开放,购买专业版 Plus 和企业版 后可使用;体验版支持一定额度免费试用,有效期一个月。

效果展示



translateText

翻译文本的接口。
接口
chat.translateText(options)
参数
参数 options 为 Object 类型,包含的属性值如下:
Name
Type
Description
sourceTextList
Array
待翻译文本数组
sourceLanguage
String
源语言。可以设置为特定语言或 "auto"。"auto" 表示自动识别源语言。
targetLanguage
String
目标语言。支持的目标语言有多种,例如:英语-"en",简体中文-"zh",法语-"fr",德语-"de"等。
返回值
Promise
示例
// 将阿拉伯文翻译成英文
let promise = chat.translateText({
sourceTextList: ['مرحبًا'],
sourceLanguage: 'auto',
targetLanguage: 'en'
});
promise.then(function(imResponse) {
// 翻译成功 translatedTextList 和 sourceTextList 的元素一一对应
const { translatedTextList } = imResponse.data;
}).catch(function(imError) {
// 翻译失败,错误码2117
console.warn('translateText error:', imError);
});
// 将英文翻译成中文
let promise = chat.translateText({
sourceTextList: ['Hello Tencent', 'Build in-app chat with Tencent Cloud Chat'],
sourceLanguage: 'auto',
targetLanguage: 'zh'
});
promise.then(function(imResponse) {
// 翻译成功 translatedTextList 和 sourceTextList 的元素一一对应
const { translatedTextList } = imResponse.data;
}).catch(function(imError) {
// 翻译失败,错误码2117
console.warn('translateText error:', imError);
});