简介
本文档提供关于数据万象创建内容翻译任务的相关 API 概览以及 SDK 示例代码。
注意:
API | 操作描述 |
提交内容翻译任务 |
功能说明
创建一个内容翻译任务。
方法原型
TranslationResponse createTranslationJob(TranslationRequest translationRequest);
请求示例
public static void createTranslationJob(COSClient client) {// 1.创建任务请求对象TranslationRequest request = new TranslationRequest();// 2. 添加请求参数 参数详情请见 API 接口文档request.setBucketName("demobucket-1251704708");request.setTag("Translation");TranslationInput input = new TranslationInput();input.setObject("demo.txt");input.setLang("zh");input.setType("txt");request.setInput(input);TranslationOutput output = new TranslationOutput();output.setRegion("ap-guangzhou");output.setBucket("demobucket-1251704708");output.setObject("translated1.txt");request.getOperation().setOutput(output);request.getOperation().getTranslation().setLang("en");request.getOperation().getTranslation().setType("txt");request.getOperation().setJobLevel("0");request.getOperation().setUserData("userData");request.setCallBack("http://xxxx.xxxx.xxxx:xxxx");request.setCallBackFormat("JSON");// 3. 调用接口,获取任务响应对象TranslationResponse response = client.createTranslationJob(request);}
参数说明
Request 中的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
Tag | Request | 创建任务的 Tag:Translation | String | 是 |
Input | Request | 待操作的对象信息 | Container | 是 |
Operation | Request | 操作规则 | Container | 是 |
CallBackFormat | Request | 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式 | String | 否 |
CallBackType | Request | 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型 | String | 否 |
CallBack | Request | 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调 | String | 否 |
CallBackMqConfig | Request | Container | 否 |
Container 类型 Input 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Object | Request.Input | 源文档文件名 单文件(docx/xlsx/html/markdown/txt):不超过800万字符 有页数的(pptx):不超过300页 文本文件(txt):不超过10MB 二进制文件(docx/pptx/xlsx):不超过60MB 图片文件(jpg/jpeg/png/webp):不超过10MB | String | 无 | 是 |
Lang | Request.Input | 文档语言类型 zh:简体中文 zh-hk:中国香港繁体中文 zh-tw:中国台湾繁体中文 zh-tr:繁体中文 en:英语 ar:阿拉伯语 de:德语 es:西班牙语 fr:法语 id:印尼语 it:意大利语 ja:日语 pt:葡萄牙语 ru:俄语 ko:韩语 km:高棉语 lo:老挝语 | String | 无 | 是 |
Type | Request.Input | 文档类型 docx pptx xlsx txt xml html(只能翻译 HTML 里的文本节点,需要通过 JS 动态加载的不进行翻译) markdown jpg jpeg png webp | String | 无 | 是 |
BasicType | Request.Input | 原始文档类型 仅在 Type = jpg/jpeg/png/webp 时使用 当值为 jpg/jpeg/png/webp 时,仅支持 txt | String | 无 | 否 |
Container 类型 Operation 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Translation | Request.Operation | 翻译参数 | Container | 无 | 是 |
Output | Request.Operation | 结果输出地址,当 NoNeedOutput 为 true 时非必选 | Container | 无 | 否 |
UserData | Request.Operation | 透传用户信息,可打印的 ASCII 码,长度不超过1024 | String | 无 | 否 |
JobLevel | Request.Operation | 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高 | String | 0 | 否 |
NoNeedOutput | Request.Operation | 仅输出结果,不生成结果文件 取值:true/false。该参数源文档类型为图片时有效 | String | false | 否 |
Container 类型 Translation 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Lang | Request.Operation.Translation | 目标语言类型 源语言类型为 zh/zh-hk/zh-tw/zh-tr 时支持:en、ar、de、es、fr、id、it、ja、it、ru、ko、km、lo、pt 源语言类型为 en 时支持:zh、zh-hk、zh-tw、zh-tr、ar、de、es、fr、id、it、ja、it、ru、ko、km、lo、pt 其他类型时支持:zh、zh-hk、zh-tw、zh-tr、en | String | 无 | 是 |
Type | Request.Operation.Translation | 文档类型,源文件类型与目标文件类型映射关系如下: docx:docx pptx:pptx xlsx:xlsx txt:txt xml:xml html:html markdown:markdown png:txt jpg:txt jpeg:txt webp:txt | String | 无 | 是 |
Container 类型 Output 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
Region | Request.Operation.Output | 存储桶的地域 | String | 是 |
Bucket | Request.Operation.Output | 存储结果的存储桶 | String | 是 |
Object | Request.Operation.Output | 输出结果的文件名 | String | 是 |
返回结果说明
成功:返回任务详情响应包装类,类中包含一个 TranslationResponse 任务详情对象。