阿里云机器翻译产品机器批量翻译服务 Java SDK 调用指南

请求参数

详情请见:机器批量翻译调用指南

下载安装

导入Maven依赖文件

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>alimt20181012</artifactId>
  <version>1.0.3</version>
</dependency>

代码示例

import com.aliyun.alimt20181012.models.*;
import com.aliyun.teaopenapi.models.*;
import com.google.gson.Gson;

public class PiLiangFanYi {
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     * 批量翻译
     */
    public static com.aliyun.alimt20181012.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "mt.aliyuncs.com";
        return new com.aliyun.alimt20181012.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.alimt20181012.Client client = PiLiangFanYi.createClient("AccessKey ID", "AccessKey Secret");
        GetBatchTranslateRequest getBatchTranslateRequest = new GetBatchTranslateRequest()
                .setFormatType("text")
                .setTargetLanguage("zh")
                .setSourceLanguage("en")
                .setSourceText("{\"11\":\"hello boy\",\"12\":\"go home\",\"13\":\"we can\"}")
                .setApiType("translate_standard")
                .setScene("general");
        // 复制代码运行请自行打印 API 的返回值
        GetBatchTranslateResponse batchTranslate = client.getBatchTranslate(getBatchTranslateRequest);
        System.out.println(new Gson().toJson(batchTranslate.body));
    }
}
上一篇:VUE学习笔记(四)


下一篇:jvm性能调优与监控之---jstat