# 机器翻译
此接口,从插件 1.1.8 开始支持
双向中英互译,输入一段中文翻译成英文,或输入一段英文翻译成中文
# 初始化
文档内插件版本号,仅做示例参考,插件最新版本,以此处为准
{
"pages": [
"pages/index/index"
],
"plugins": {
"chatbot": {
"version": "1.2.23",
"provider": "wx8c631f7e9f2465e1"
}
},
"requiredBackgroundModes": [
"audio"
],
"sitemapLocation": "sitemap.json"
}
var plugin = requirePlugin("chatbot");
App({
onLaunch: function () {
plugin.init({
appid: "P5Ot9PHJDechCYqDFAW1AiK6OtG3Ja", //小程序示例账户,仅供学习和参考
openid: "", //用户的openid必填
success: () => {}, //非必填
fail: (error) => {}, //非必填
});
},
});
# 调用机器翻译接口
- 中译英
const txt = "北京的天气怎么样?";
plugin.api.nlp("translate_cn2en", { q: txt }).then((res) => {
console.log("translate_cn2en result : ", res);
});
- 英译中
const txt = "what are you doing?";
plugin.api.nlp("translate_en2cn", { q: txt }).then((res) => {
console.log("translate_en2cn result : ", res);
});
# 请求参数
字段 | 类型 | 描述 |
---|---|---|
q | string | 输入文本,UTF-8 编码,最大长度为 1024 个字 |
# 返回结果示例
- 中译英
{
"result": "What about the weather in Beijing?"
}
- 英译中
{
"result": "你在干嘛"
}