一、功能描述
注意:说明:
注意:文本翻译是增值付费功能,计费明细请参见 增值服务计费说明。
二、translateText
翻译文本的接口。
接口
chat.translateText(options)
参数
参数 options 为 Object 类型,包含的属性值如下:
| 名称 | 类型 | 描述 |
| 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);});