tencent cloud

Boost Engagement with Tencent RTC Free TrialFree video and chat features await!

文档反馈

即时通信 IM

JavaScript

最后更新时间:2024-10-30 11:43:57

功能描述

消息翻译目前仅支持手动调接口翻译文本消息内容,图片、视频、文件、语音、自定义消息等非文本内容均不支持翻译。
说明:
文本翻译是增值付费功能,处于内测阶段,您可通过 Telegram 技术交流群组 联系我们为您开通体验完整功能。

效果展示



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);
});


产品类别

联系我们

联系我们,为您的业务提供专属服务。

技术支持

如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

7x24 电话支持
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon