文档翻译 Document Translation
上传文档进行全文翻译,支持 PDF、Word、PPT、Excel、TXT、HTML 等格式,保留原始排版、字体、表格和图片。提供同步直返和异步任务两种模式,可结合术语库和翻译记忆库提升专业文档翻译质量,适用于合同、论文、报告、说明书等多种场景。 Upload documents for full-text translation. Supports PDF, Word, PPT, Excel, TXT, HTML and more, preserving original layout, fonts, tables, and images. Offers sync direct-return and async task modes, with glossary and translation memory integration for professional documents like contracts, papers, reports, and manuals.
快速概览 Quick Overview
属性 Attribute 说明 Description
翻译端点 Translate Endpoint POST /v1/document/translate
任务查询端点 Task Query Endpoint GET /v1/document/tasks/{task_id}
下载端点 Download Endpoint GET /v1/document/tasks/{task_id}/download
认证 Authentication Bearer Token(Authorization 请求头) Bearer Token in Authorization header
请求体 Request Body multipart/form-data(文件上传)multipart/form-data (file upload)
文件上限 Max File Size 50 MB(异步模式 100 MB) 50 MB (100 MB in async mode)
支持格式 Supported Formats PDF / Word / PPT / Excel / TXT / HTML / Markdown / RTF PDF / Word / PPT / Excel / TXT / HTML / Markdown / RTF
排版保留 Layout Preservation 保留原始排版、字体、表格、图片、页眉页脚 Preserves original layout, fonts, tables, images, headers/footers
处理模式 Processing Mode 同步直返(小文件)/ 异步任务(大文件推荐) Sync direct-return (small files) / Async task (recommended for large files)
请求端点 Endpoint
POST /v1/document/translate
认证 Authentication
所有 API 请求需在 HTTP Header 中携带 Access Token。
All API requests must include an Access Token in the HTTP Header.
Authorization: Bearer {access_token}
请求头 Request Headers
请求头 Header 必填 Required 说明 Description
Authorizationrequired 格式 Bearer {access_token},用于身份认证 Format: Bearer {access_token}, used for authentication
Content-Typerequired 固定为 multipart/form-data,请勿手动设置,让 HTTP 客户端自动生成 Must be multipart/form-data; do not set manually, let the HTTP client generate it
请求参数 Request Parameters
ℹ️ Content-Type 本端点使用 multipart/form-data 进行文件上传,请勿手动设置 Content-Type,让 HTTP 客户端自动生成。 This endpoint uses multipart/form-data for file upload; do not set Content-Type manually, let the HTTP client auto-generate it.
参数 Parameter 类型 Type 必填 Required 说明 Description
file file / string required 待翻译文档(multipart 上传)或文档 URL。同步模式 ≤50MB,异步模式 ≤100MB Document to translate (multipart) or document URL. ≤50MB sync, ≤100MB async
source_lang string required 源语言代码,auto 为自动检测。显式指定可提升准确率。详见语种列表 Source language code; auto for auto-detection. Explicit specifying improves accuracy. See Language List
target_lang string required 目标语言代码,如 en、zh、ja Target language code, e.g. en, zh, ja
output_format string optional 输出格式:same(保持原格式,默认)/ txt(纯文本)/ pdf / docx Output format: same (default) / txt / pdf / docx
glossary_id string optional 关联术语库 ID,确保专业术语翻译一致 Associated glossary ID for consistent terminology
tm_id string optional 关联翻译记忆库 ID,复用历史翻译提升一致性和速度 Associated translation memory ID for consistency and speed
preserve_formatting boolean optional 是否保留原始排版(字体、颜色、表格、图片),默认 true Preserve original formatting (fonts, colors, tables, images), default true
translate_mode string optional 翻译模式:sync(同步直返,默认)/ async(异步任务)。大文件推荐 async Translate mode: sync (default) / async. Async recommended for large files
ocr_fallback boolean optional 扫描版 PDF 是否自动启用 OCR 识别后翻译,默认 false Auto-enable OCR for scanned PDFs, default false
callback_url string optional 异步回调地址。async 模式下翻译完成后通过 HTTP POST 推送结果 Async callback URL; receives POST result on completion in async mode
支持的文件格式 Supported Formats
格式 Format 扩展名 Extensions 排版保留 Layout Preserved 说明 Notes
PDF .pdf
✅
支持文本版和扫描版(需开启 OCR),保留页面布局、图片、表格
Supports text-based and scanned (OCR required); preserves layout, images, tables
Microsoft Word .docx, .doc
✅
保留段落样式、页眉页脚、目录、批注
Preserves paragraph styles, headers/footers, TOC, comments
Microsoft PowerPoint .pptx, .ppt
✅
保留幻灯片布局、母版、动画文本、备注
Preserves slide layouts, masters, animation text, notes
Excel .xlsx, .xls
✅
保留单元格格式、公式、图表、数据透视表
Preserves cell formats, formulas, charts, pivot tables
纯文本 Plain Text .txt
—
无排版,按纯文本处理,速度最快
No layout; processed as plain text, fastest
HTML .html, .htm
✅
保留 HTML 结构、CSS 样式、内联脚本不翻译
Preserves HTML structure, CSS styles; inline scripts not translated
Markdown .md, .markdown
✅
保留 Markdown 语法标记,仅翻译正文内容
Preserves Markdown syntax; only body content translated
RTF .rtf
✅
保留富文本格式、字体、段落属性
Preserves rich text format, fonts, paragraph properties
💡 格式选择建议
💡 Format Selection Tips
需要保留排版的正式文档优先使用 PDF 或 Word 格式上传
For formal documents requiring layout preservation, prefer PDF or Word
扫描版 PDF 需设置 ocr_fallback=true,否则图片中的文字不会被翻译
Scanned PDFs require ocr_fallback=true; otherwise text in images won't be translated
仅需提取文本翻译无需排版时,设置 output_format=txt 可加快处理速度
When only text translation is needed, set output_format=txt for faster processing
请求示例 Request Examples
cURL
Python
JavaScript
Java
Go
# 同步模式:基础文档翻译
curl -X POST https://api.itranslator.cc/v1/document/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@report.pdf" \
-F "source_lang=zh" \
-F "target_lang=en" \
-F "output_format=same" \
-o report_en.pdf
# 异步模式 + 术语库 + 翻译记忆库(适合专业文档)
curl -X POST https://api.itranslator.cc/v1/document/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@contract.docx" \
-F "source_lang=zh" \
-F "target_lang=en" \
-F "translate_mode=async" \
-F "glossary_id=gl_legal_001" \
-F "tm_id=tm_law_2024" \
-F "preserve_formatting=true" \
-F "callback_url=https://myapp.com/webhook/doc-translate"
# 扫描版 PDF(自动 OCR)
curl -X POST https://api.itranslator.cc/v1/document/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@scanned_manual.pdf" \
-F "source_lang=auto" \
-F "target_lang=zh" \
-F "ocr_fallback=true" \
-F "translate_mode=async" \
-F "callback_url=https://myapp.com/webhook/doc-translate"
import requests
import time
token = "YOUR_ACCESS_TOKEN"
url = "https://api.itranslator.cc/v1/document/translate"
# 同步模式:直接获取翻译后的文件
with open("report.pdf", "rb") as f:
resp = requests.post(
url,
headers={"Authorization": f"Bearer {token}"},
files={"file": f},
data={
"source_lang": "zh",
"target_lang": "en",
"output_format": "same"
}
)
with open("report_en.pdf", "wb") as out:
out.write(resp.content)
print(f"✅ 翻译完成,字符数: {resp.headers.get('X-Char-Count')}")
# 异步模式:提交任务 + 轮询状态
with open("contract.docx", "rb") as f:
resp = requests.post(
url,
headers={"Authorization": f"Bearer {token}"},
files={"file": f},
data={
"source_lang": "zh",
"target_lang": "en",
"translate_mode": "async",
"glossary_id": "gl_legal_001",
"tm_id": "tm_law_2024",
"preserve_formatting": "true",
"callback_url": "https://myapp.com/webhook/doc-translate"
}
)
task = resp.json()
task_id = task["task_id"]
print(f"任务已提交: {task_id}, 状态: {task['status']}")
# 轮询任务状态
while True:
status_resp = requests.get(
f"https://api.itranslator.cc/v1/document/tasks/{task_id}",
headers={"Authorization": f"Bearer {token}"}
).json()
if status_resp["status"] in ("succeeded", "failed"):
break
time.sleep(5)
if status_resp["status"] == "succeeded":
# 下载翻译结果
download_resp = requests.get(
f"https://api.itranslator.cc/v1/document/tasks/{task_id}/download",
headers={"Authorization": f"Bearer {token}"}
)
with open("contract_en.docx", "wb") as out:
out.write(download_resp.content)
print("✅ 翻译文件已下载")
const axios = require("axios");
const fs = require("fs");
const token = process.env.API_TOKEN;
// 异步模式提交翻译任务
const form = new FormData();
form.append("file", fs.createReadStream("contract.docx"));
form.append("source_lang", "zh");
form.append("target_lang", "en");
form.append("translate_mode", "async");
form.append("glossary_id", "gl_legal_001");
form.append("preserve_formatting", "true");
form.append("callback_url", "https://myapp.com/webhook/doc-translate");
const resp = await axios.post(
"https://api.itranslator.cc/v1/document/translate",
form,
{ headers: { ...form.getHeaders(), Authorization: `Bearer ${token}` } }
);
console.log("任务已提交:", resp.data.task_id);
// 查询任务状态
const status = await axios.get(
`https://api.itranslator.cc/v1/document/tasks/${resp.data.task_id}`,
{ headers: { Authorization: `Bearer ${token}` } }
);
console.log("当前状态:", status.data.status, "进度:", status.data.progress + "%");
// 下载翻译结果(状态为 succeeded 后)
if (status.data.status === "succeeded") {
const file = await axios.get(
`https://api.itranslator.cc/v1/document/tasks/${resp.data.task_id}/download`,
{ headers: { Authorization: `Bearer ${token}` }, responseType: "arraybuffer" }
);
fs.writeFileSync("contract_en.docx", file.data);
console.log("✅ 翻译文件已下载");
}
import okhttp3.*;
import java.io.*;
OkHttpClient client = new OkHttpClient();
// 同步模式:直接获取翻译后的文件流
RequestBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "report.pdf",
RequestBody.create(new File("report.pdf"),
MediaType.parse("application/pdf")))
.addFormDataPart("source_lang", "zh")
.addFormDataPart("target_lang", "en")
.addFormDataPart("output_format", "same")
.build();
Request request = new Request.Builder()
.url("https://api.itranslator.cc/v1/document/translate")
.header("Authorization", "Bearer " + token)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
try (FileOutputStream fos = new FileOutputStream("report_en.pdf")) {
fos.write(response.body().bytes());
}
System.out.println("✅ 字符数: " +
response.header("X-Char-Count"));
}
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("report.pdf")
defer file.Close()
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
fw, _ := writer.CreateFormFile("file", "report.pdf")
io.Copy(fw, file)
writer.WriteField("source_lang", "zh")
writer.WriteField("target_lang", "en")
writer.WriteField("output_format", "same")
writer.Close()
req, _ := http.NewRequest("POST",
"https://api.itranslator.cc/v1/document/translate", &buf)
req.Header.Set("Authorization", "Bearer "+os.Getenv("API_TOKEN"))
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("report_en.pdf")
defer out.Close()
io.Copy(out, resp.Body)
fmt.Println("✅ 翻译完成, 字符数:", resp.Header.Get("X-Char-Count"))
}
Copy
响应说明 Response Description
根据 translate_mode 不同,响应方式不同:
Response varies based on translate_mode:
模式 Mode 响应类型 Response Type 适用场景 Best For
sync
二进制文件流
Binary file stream
小文件(<10MB),翻译完成后直接返回文件
Small files (<10MB); returns file directly
async
JSON(任务信息)
JSON (task info)
大文件(10~100MB),需轮询或回调获取结果
Large files (10~100MB); poll or use callback
响应字段说明(异步模式) Response Fields (Async Mode)
字段 Field 类型 Type 说明 Description
task_id string 翻译任务唯一 ID,用于查询状态和下载结果 Unique task ID for status query and download
status string 任务状态:pending(排队)/ processing(翻译中)/ succeeded(成功)/ failed(失败) Status: pending / processing / succeeded / failed
progress integer 翻译进度百分比(0~100) Translation progress percentage (0~100)
source_lang string 源语言代码 Source language code
target_lang string 目标语言代码 Target language code
char_count integer 翻译字符数(计费依据) Translated character count (billing basis)
created_at string 任务创建时间(ISO 8601 UTC) Task creation time (ISO 8601 UTC)
completed_at string 任务完成时间(仅 succeeded 时返回) Completion time (only when succeeded)
响应示例 Response Examples
同步模式(二进制文件流) Sync Mode (Binary Stream)
成功时直接返回翻译后的文档二进制流,响应头包含:
Returns the translated document as a binary stream on success with headers:
Content-Type: application/pdf
Content-Disposition: attachment; filename="report_en.pdf"
X-Char-Count: 15420
X-Translated-Pages: 12
异步模式(提交任务) Async Mode (Submit Task)
{
"task_id": "doc-task-9f8e7d6c",
"status": "pending",
"source_lang": "zh",
"target_lang": "en",
"progress": 0,
"created_at": "2026-07-21T09:30:00Z"
}
异步回调推送(翻译完成) Async Callback (Completed)
翻译完成后,结果通过 HTTP POST 推送到 callback_url:
On completion, the result is pushed via HTTP POST to the callback_url:
{
"task_id": "doc-task-9f8e7d6c",
"status": "succeeded",
"source_lang": "zh",
"target_lang": "en",
"progress": 100,
"char_count": 28560,
"download_url": "https://api.itranslator.cc/v1/document/tasks/doc-task-9f8e7d6c/download",
"created_at": "2026-07-21T09:30:00Z",
"completed_at": "2026-07-21T09:31:45Z"
}
查询任务状态 Query Task Status
GET /v1/document/tasks/{task_id}
查询异步翻译任务的状态和进度。建议轮询间隔 5~10 秒,避免过于频繁。
Query the status and progress of an async translation task. Recommended polling interval: 5~10 seconds.
curl -X GET https://api.itranslator.cc/v1/document/tasks/doc-task-9f8e7d6c \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Copy
{
"task_id": "doc-task-9f8e7d6c",
"status": "processing",
"source_lang": "zh",
"target_lang": "en",
"progress": 65,
"char_count": 0,
"created_at": "2026-07-21T09:30:00Z"
}
下载翻译结果 Download Translated File
GET /v1/document/tasks/{task_id}/download
下载已完成翻译的文档。仅当任务状态为 succeeded 时可调用,翻译结果保留 24 小时。
Download the translated document. Only available when task status is succeeded; results are retained for 24 hours.
curl -X GET https://api.itranslator.cc/v1/document/tasks/doc-task-9f8e7d6c/download \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o contract_en.docx
Copy
错误码 Error Codes
HTTP Code 错误码 Code 说明 Description
200 0成功 Success
400 1001参数错误,请检查必填参数和参数格式 Invalid parameter; check required fields and format
400 3004不支持的文件格式 Unsupported file format
400 3005上传的文件为空或已损坏 Uploaded file is empty or corrupted
400 3006文档内容为空,无可翻译文本 Document has no translatable text
400 3007文档已加密或受密码保护,无法解析 Document is encrypted or password-protected; cannot parse
400 3008扫描版 PDF 未开启 OCR,无法提取文本 Scanned PDF without OCR enabled; cannot extract text
400 3009指定的 glossary_id 或 tm_id 不存在或无权访问 Specified glossary_id or tm_id does not exist or access denied
401 2001认证失败,Token 无效或已过期 Authentication failed; invalid or expired token
403 2003无权限访问该资源 Access denied; insufficient permissions
404 2005指定的 task_id 不存在或已过期(结果保留 24 小时) Specified task_id does not exist or has expired (results retained 24 hours)
409 3010任务尚未完成,无法下载(仅 succeeded 状态可下载) Task not yet complete; download only available when status is succeeded
413 3001文件大小超出限制(同步 50MB / 异步 100MB) File size exceeds limit (50MB sync / 100MB async)
429 4001请求频率超限,请稍后重试 Rate limit exceeded; please retry later
456 4002套餐配额已用尽,请升级或等待重置 Plan quota exhausted; upgrade or wait for reset
500 5001服务器处理失败,请重试或联系技术支持 Server processing failed; retry or contact support
503 5002服务暂时不可用,建议稍后重试 Service temporarily unavailable; retry later
最佳实践 Best Practices
选择合适的处理模式 :小于 10MB 的文档使用同步模式直接获取结果;大于 10MB 或页数超过 50 页的文档使用异步模式,避免请求超时。
Choose the Right Mode : Use sync mode for documents under 10MB; use async mode for files over 10MB or 50+ pages to avoid timeouts.
专业文档结合术语库 :法律、医疗、技术文档翻译时关联 glossary_id 确保术语一致,配合 tm_id 复用历史翻译提升连贯性。
Use Glossary for Pro Docs : Link glossary_id for legal, medical, and technical documents to ensure terminology consistency; use tm_id to reuse past translations.
扫描版 PDF 处理 :对于图片型 PDF,务必设置 ocr_fallback=true,否则图片中的文字无法被翻译。
Handle Scanned PDFs : For image-based PDFs, always set ocr_fallback=true; otherwise text in images won't be translated.
显式指定源语言 :尽量指定 source_lang 而非 auto,可减少检测时间并避免多语言混排时的误判。
Specify Source Language : Set source_lang explicitly instead of auto to reduce detection time and avoid misidentification in mixed-language documents.
异步任务轮询策略 :轮询间隔建议 5~10 秒,避免过于频繁。优先使用 callback_url 回调模式替代轮询。
Async Polling Strategy : Poll every 5~10 seconds; prefer callback_url over polling.
及时下载结果 :异步翻译结果保留 24 小时,请在有效期内下载,过期后需重新提交翻译任务。
Download Promptly : Async results are retained for 24 hours; download within the validity period or resubmit.
应用场景 Use Cases
场景 Scenario 推荐配置 Recommended Config 说明 Notes
📄 合同/法律文档
📄 Legal Documents
异步 + 术语库 + 翻译记忆库
Async + glossary + TM
保留排版,确保法律术语翻译一致准确
Preserve layout; ensure consistent and accurate legal terminology
🎓 论文/学术
🎓 Academic Papers
同步 + PDF + 保留排版
Sync + PDF + preserve layout
翻译学术论文、研究报告,保留公式和引用格式
Translate papers and reports; preserve formulas and citations
📊 商务报告
📊 Business Reports
同步 + Word/PPT
Sync + Word/PPT
翻译 PPT 演示文稿和 Word 报告,保留图表和母版
Translate PPT and Word reports; preserve charts and masters
🔧 产品说明书
🔧 Product Manuals
异步 + 术语库 + OCR
Async + glossary + OCR
多语言产品手册批量翻译,扫描版自动 OCR 识别
Batch translate multi-language manuals; auto-OCR for scanned versions
📈 财务报表
📈 Financial Statements
同步 + Excel + 保留格式
Sync + Excel + preserve format
翻译 Excel 表格,保留公式、数字格式和图表
Translate Excel; preserve formulas, number formats, and charts
🌐 网页内容
🌐 Web Content
同步 + HTML
Sync + HTML
翻译 HTML 页面,保留结构和 CSS 样式
Translate HTML pages; preserve structure and CSS
使用说明
Notes
文件上传使用 multipart/form-data 编码,Content-Type 请勿手动设置,让 HTTP 客户端自动生成。
Use multipart/form-data encoding; let the HTTP client auto-generate Content-Type.
同步模式直接返回二进制文件流;异步模式返回 JSON 任务信息,需通过查询接口或回调获取下载链接。
Sync mode returns binary stream; async mode returns JSON task info; retrieve download link via query API or callback.
大文件建议使用异步任务模式,翻译结果保留 24 小时,请及时下载。
For large files, use async task mode; results retained 24 hours, download promptly.
请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
Do not expose your Access Token in client-side code; use a backend proxy.