Document Translation Tutorial

更新时间:
复制 MD 格式

This document describes how to translate documents using the Document Translation API.

Function Introduction

The document translation feature parses the text content of a document, calls the machine translation engine to translate the text, and then generates a new file that contains the translated text in the same format as the original document.

Note

When a PDF document is translated, a DOCX document is returned.

Limits

  • Supported document languages: For more information, see Language Codes.

  • Supported document types: doc, docx, xls, xlsx, csv, ppt, pptx, txt, srt, html, htm, xml, xhtml, json, xliff, tmx, dita, md, markdown, idml, and pdf.

  • The file size cannot exceed 50 MB. For doc, docx, csv, txt, srt, pdf, html, htm, xml, xhtml, json, xliff, tmx, dita, md, markdown, and idml files, the number of characters cannot exceed 1 million. For xls and xlsx files, the number of cells cannot exceed 100,000.

  • The file URL (FileUrl) must be publicly accessible. The URL must be a domain name, not an IP address. The URL cannot contain spaces or Chinese characters.

  • The callback URL (CallbackUrl) must be publicly accessible. The URL must be a domain name, not an IP address, and cannot contain spaces.

  • The URL of the translated file (TranslateFileUrl) is valid for one hour. After you confirm that the document translation task is successful, you must download the translated file within one hour.

Steps

  • Create a document translation task (CreateDocTranslateTask)

  • Call the CreateDocTranslateTask API to create a document translation task. Pass the document address in the FileUrl parameter. The FileUrl must be a publicly accessible URL. We recommend that you host the document on Object Storage Service (OSS). This allows the Machine Translation service to read the document using Object-related commands.

  • After the task is created, the API returns a task ID (TaskId). Call the GetDocTranslateTask API with the TaskId to query the status of the task.

  • After you call the GetDocTranslateTask API and confirm that the task status is translated, you can retrieve the URL of the translated document from the TranslateFileUrl parameter in the response.

Task status codes

Status

Status code

Description

ready

Preparing

The task has been created and is awaiting translation.

translating

Translating

The document is being translated.

translated

Translated

The document has been translated successfully.

error

Translation error

The document translation failed.