快速入门:异步文档翻译

异步批处理翻译允许在单个请求中提交多个文档或大型文件进行翻译。 该服务并行处理文档,并将转换后的输出写入Azure Blob 存储目标容器。 由于该操作是异步运行的,因此你需要通过轮询作业 ID 来跟踪进度,而不是等待立即返回响应。 当您需要翻译大批量内容,或文件过大而无法使用同步请求处理时,请使用此方法。

先决条件

  • 一个Azure AI 翻译 资源
  • 具有源容器(输入文件)和目标容器(输出文件)的Azure Blob 存储 帐户
  • 为两个容器配置的 SAS 令牌托管标识

有关详细信息,请参阅 先决条件和设置

步骤 1:上传文档

在提交翻译请求之前,请将源文档上传到指定为输入位置的Blob 存储容器。 服务在作业运行时从该容器中读取文档。

步骤 2:授权访问Blob 存储帐户

API 需要授权才能从源容器读取并写入目标容器。 在生成请求之前设置以下授权方法之一:

步骤 3:提交批处理翻译请求

使用 JSON 正文将 POST 请求发送到 /batches 终结点,该正文指定源和目标容器 URL、目标语言和任何其他选项。 选择与翻译引擎和要求匹配的选项。

基于 NMT 的翻译

将此选项用于标准神经机器翻译。

curl -X POST "{endpoint}/translator/document/batches?api-version=2026-03-01" \
  -H "Ocp-Apim-Subscription-Key: {key}" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [
      {
        "source": {
          "sourceUrl": "{source-container-SAS-URL} or {source-container-name-for-managed-identity}"
        },
        "targets": [
          {
            "targetUrl": "{target-container-SAS-URL} or {target-container-name-for-managed-identity}",
            "language": "fr"
          }
        ]
      }
    ]
  }'

翻译Word和PowerPoint文档中的图像

使用此选项可以翻译嵌入在图像中的Word(.docx)和PowerPoint(.pptx)文件中的文本。 在translateWithinImage对象中,将true设置为options

curl -X POST "{endpoint}/translator/document/batches?api-version=2026-03-01" \
  -H "Ocp-Apim-Subscription-Key: {key}" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [
      {
        "source": {
          "sourceUrl": "{source-container-SAS-URL} or {source-container-name-for-managed-identity}"
        },
        "targets": [
          {
            "targetUrl": "{target-container-SAS-URL} or {target-container-name-for-managed-identity}",
            "language": "fr"
          }
        ]
      }
    ],
    "options": { "translateWithinImage": true }
  }'

步骤 4:检查状态

由于翻译以异步方式运行,因此服务会立即返回 202 Accepted 响应而不是已翻译的文档。 若要跟踪进度,请从 operation-location 响应中的标头中提取作业 ID,并轮询该 URL,直到作业完成。

operation-location: https://{your-endpoint}/translator/document/batches/{jobId}?api-version=2026-03-01

示例响应

  • 状态代码: 202
  • 状态: Accepted


response headers: {
  'Transfer-Encoding': 'chunked',
  'Content-Type': 'application/json; charset=utf-8',
  'x-requestid': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  'operation-location': 'https://{your-endpoint}/translator/document/batches/jjjjjjjj-jjjj-jjjj-jjjj-jjjjjjjjjjjj?api-version=2026-03-01',
  'x-envoy-upstream-service-time': '366',
  'apim-request-id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'x-ms-region': 'China North',
  'Date': 'Mon, 04 May 2026 16:06:08 GMT'
           }

若要监控进度,请使用 operation-location URL 轮询作业状态。 有关详细信息,请参阅 “获取翻译作业状态”。

步骤 5:查看结果

当作业状态显示为成功时,Azure Blob 存储帐户的目标容器中提供了已翻译的文档。 直接从容器下载它们,或使用Azure SDK以编程方式访问它们。