文档翻译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 EndpointPOST /v1/document/translate
任务查询端点Task Query EndpointGET /v1/document/tasks/{task_id}
下载端点Download EndpointGET /v1/document/tasks/{task_id}/download
认证AuthenticationBearer Token(Authorization 请求头)Bearer Token in Authorization header
请求体Request Bodymultipart/form-data(文件上传)multipart/form-data (file upload)
文件上限Max File Size50 MB(异步模式 100 MB)50 MB (100 MB in async mode)
支持格式Supported FormatsPDF / Word / PPT / Excel / TXT / HTML / Markdown / RTFPDF / 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
filefile / stringrequired待翻译文档(multipart 上传)或文档 URL。同步模式 ≤50MB,异步模式 ≤100MBDocument to translate (multipart) or document URL. ≤50MB sync, ≤100MB async
source_langstringrequired源语言代码,auto 为自动检测。显式指定可提升准确率。详见语种列表Source language code; auto for auto-detection. Explicit specifying improves accuracy. See Language List
target_langstringrequired目标语言代码,如 enzhjaTarget language code, e.g. en, zh, ja
output_formatstringoptional输出格式:same(保持原格式,默认)/ txt(纯文本)/ pdf / docxOutput format: same (default) / txt / pdf / docx
glossary_idstringoptional关联术语库 ID,确保专业术语翻译一致Associated glossary ID for consistent terminology
tm_idstringoptional关联翻译记忆库 ID,复用历史翻译提升一致性和速度Associated translation memory ID for consistency and speed
preserve_formattingbooleanoptional是否保留原始排版(字体、颜色、表格、图片),默认 truePreserve original formatting (fonts, colors, tables, images), default true
translate_modestringoptional翻译模式:sync(同步直返,默认)/ async(异步任务)。大文件推荐 asyncTranslate mode: sync (default) / async. Async recommended for large files
ocr_fallbackbooleanoptional扫描版 PDF 是否自动启用 OCR 识别后翻译,默认 falseAuto-enable OCR for scanned PDFs, default false
callback_urlstringoptional异步回调地址。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
💡 格式选择建议
  • 需要保留排版的正式文档优先使用 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 -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"

响应说明

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_idstring翻译任务唯一 ID,用于查询状态和下载结果Unique task ID for status query and download
statusstring任务状态:pending(排队)/ processing(翻译中)/ succeeded(成功)/ failed(失败)Status: pending / processing / succeeded / failed
progressinteger翻译进度百分比(0~100)Translation progress percentage (0~100)
source_langstring源语言代码Source language code
target_langstring目标语言代码Target language code
char_countinteger翻译字符数(计费依据)Translated character count (billing basis)
created_atstring任务创建时间(ISO 8601 UTC)Task creation time (ISO 8601 UTC)
completed_atstring任务完成时间(仅 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"
{
  "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

错误码

Error Codes

HTTP Code错误码Code说明Description
2000成功Success
4001001参数错误,请检查必填参数和参数格式Invalid parameter; check required fields and format
4003004不支持的文件格式Unsupported file format
4003005上传的文件为空或已损坏Uploaded file is empty or corrupted
4003006文档内容为空,无可翻译文本Document has no translatable text
4003007文档已加密或受密码保护,无法解析Document is encrypted or password-protected; cannot parse
4003008扫描版 PDF 未开启 OCR,无法提取文本Scanned PDF without OCR enabled; cannot extract text
4003009指定的 glossary_id 或 tm_id 不存在或无权访问Specified glossary_id or tm_id does not exist or access denied
4012001认证失败,Token 无效或已过期Authentication failed; invalid or expired token
4032003无权限访问该资源Access denied; insufficient permissions
4042005指定的 task_id 不存在或已过期(结果保留 24 小时)Specified task_id does not exist or has expired (results retained 24 hours)
4093010任务尚未完成,无法下载(仅 succeeded 状态可下载)Task not yet complete; download only available when status is succeeded
4133001文件大小超出限制(同步 50MB / 异步 100MB)File size exceeds limit (50MB sync / 100MB async)
4294001请求频率超限,请稍后重试Rate limit exceeded; please retry later
4564002套餐配额已用尽,请升级或等待重置Plan quota exhausted; upgrade or wait for reset
5005001服务器处理失败,请重试或联系技术支持Server processing failed; retry or contact support
5035002服务暂时不可用,建议稍后重试Service temporarily unavailable; retry later

最佳实践

Best Practices

  1. 选择合适的处理模式:小于 10MB 的文档使用同步模式直接获取结果;大于 10MB 或页数超过 50 页的文档使用异步模式,避免请求超时。
  2. Choose the Right Mode: Use sync mode for documents under 10MB; use async mode for files over 10MB or 50+ pages to avoid timeouts.
  3. 专业文档结合术语库:法律、医疗、技术文档翻译时关联 glossary_id 确保术语一致,配合 tm_id 复用历史翻译提升连贯性。
  4. 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.
  5. 扫描版 PDF 处理:对于图片型 PDF,务必设置 ocr_fallback=true,否则图片中的文字无法被翻译。
  6. Handle Scanned PDFs: For image-based PDFs, always set ocr_fallback=true; otherwise text in images won't be translated.
  7. 显式指定源语言:尽量指定 source_lang 而非 auto,可减少检测时间并避免多语言混排时的误判。
  8. Specify Source Language: Set source_lang explicitly instead of auto to reduce detection time and avoid misidentification in mixed-language documents.
  9. 异步任务轮询策略:轮询间隔建议 5~10 秒,避免过于频繁。优先使用 callback_url 回调模式替代轮询。
  10. Async Polling Strategy: Poll every 5~10 seconds; prefer callback_url over polling.
  11. 及时下载结果:异步翻译结果保留 24 小时,请在有效期内下载,过期后需重新提交翻译任务。
  12. 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
使用说明
  • 文件上传使用 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.