天天看點

阿裡雲機器翻譯NodeJS使用Demo

SDK 安裝

npm install @alicloud/pop-core -S           

Code Sample

const Core = require('@alicloud/pop-core');

var client = new Core({
  accessKeyId: 'LTAIOZZg********',
  accessKeySecret: 'v7CjUJCMk7j9aKduMA************',
  endpoint: 'https://mt.cn-hangzhou.aliyuncs.com',
  apiVersion: '2018-10-12'
});

var params = {
  "RegionId": "cn-hangzhou",
  "FormatType": "text",
  "SourceLanguage": "zh",
  "TargetLanguage": "en",
  "SourceText": "北京歡迎你"
}

var requestOption = {
  method: 'POST'
};

client.request('TranslateGeneral', params, requestOption).then((result) => {
  console.log(JSON.stringify(result));
}, (ex) => {
  console.log(ex);
})           

The Result

阿裡雲機器翻譯NodeJS使用Demo

參考連結

機器翻譯通用版調用指南 阿裡雲常見參數擷取位置

繼續閱讀