全部产品
Search
文档中心

机器翻译:机器翻译调用方式

更新时间:Dec 07, 2022

机器翻译功能效果演示请参考阿里巴巴机器翻译门户网站,具体接口调用流程请参考各个机器翻译接入指南,示例请求(java):

服务地址

地域

接入地址

杭州

mt.cn-hangzhou.aliyuncs.com

请求体与结果返回(普通版)

public class SampleRequest {
    public static void main(String[] args) {        
      String serviceURL = "http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/ecommerce";  
          String accessKeyId = "<yourAccessKeyId>";// 使用您的阿里云访问密钥 AccessKeyId  
          String accessKeySecret = "<yourAccessKeySecret>"; // 使用您的阿里云访问密钥  
          String postBody = "{\n" +  
        " \"FormatType\": \"text\",\n" +  
        " \"SourceLanguage\": \"zh\",\n" +  
        " \"TargetLanguage\": \"en\",\n" +  
        " \"SourceText\": \"大疆无人机\",\n" +  
        " \"Scene\": \"title\"\n" +  
        "}";
// Sender代码请参考帮助文档“签名方法”  
String result =  Sender.sendPost(serviceURL, postBody, accessKeyId, accessKeySecret);  
System.out.println(result);
    }
}
                        

请求体与结果返回(语种自动识别版)

若想使用语种自动识别功能,需设置SourceLanguage=auto,其他调用参数与普通版一致。

public class SampleRequest {
    public static void main(String[] args) {        
      String serviceURL = "http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/ecommerce";  
          String accessKeyId = "<yourAccessKeyId>";// 使用您的阿里云访问密钥 AccessKeyId  
          String accessKeySecret = "<yourAccessKeySecret>"; // 使用您的阿里云访问密钥  
          String postBody = "{\n" +  
        " \"FormatType\": \"text\",\n" +  
        " \"SourceLanguage\": \"auto\",\n" +  
        " \"TargetLanguage\": \"en\",\n" +  
        " \"SourceText\": \"大疆无人机\",\n" +  
        " \"Scene\": \"title\"\n" +  
        "}";
// Sender代码请参考帮助文档“签名方法”  
String result =  Sender.sendPost(serviceURL, postBody, accessKeyId, accessKeySecret);  
System.out.println(result);
    }
}
                        

机器翻译版本

API 版本

接入地址

通用版本

http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/general

专业版本

http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/ecommerce

正常返回

请求正常结果,为JSON字符串。

错误返回

{"errorCode":"errorCode","errorMsg":"错误消息"}
                        

接口限制

接口限制、参数说明请参考具体开发指南

字符编码

请求及返回结果都使用 UTF-8 字符集进行编码。