Document translation tutorial
This document describes how to translate documents using the document translation API.
Introduction
Document translation parses text from a document and uses the Machine Translation engine to translate it. The service then creates a new file that contains the translated text in the same format as the original document.
Limits
- Supported 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.
- File size: Up to 50 MB.
- The file URL (
FileUrl) must be publicly accessible, use a domain name instead of an IP address, and not contain spaces. Avoid using Chinese characters in the URL. - The callback URL (
CallbackUrl) must be publicly accessible, use a domain name instead of an IP address, and not contain spaces. - The result file URL (
TranslateFileUrl) is valid for one hour. After the document translation task is complete, download the result file within this one-hour period.
Steps
You can create a document translation task (
CreateDocTranslateTask).Call the
CreateDocTranslateTaskAPI to create a document translation task. Pass the document location in theFileUrlparameter. TheFileUrlmust be a publicly accessible URL. Host your document on Object Storage Service (OSS). Then, generate a signed URL to allow the Machine Translation service to read the document.After the task is created, the API returns a task ID (
TaskId). Use theGetDocTranslateTaskAPI and theTaskIdto query the status of the translation task.When the
GetDocTranslateTaskAPI returns a task status oftranslated, retrieve the URL of the translated document from theTranslateFileUrlfield in the response.
Task status codes
| Status | Status code | Description |
| ready | Preparing | The task was created and is waiting for translation. |
| translating | Translating | The translation is in progress. |
| translated | Translated | The document was translated successfully. |
| error | Translation error | An error occurred during document translation. |