文档翻译 SDK

文档翻译是一项基于云的Azure 翻译器功能。 它支持跨支持的语言和文件格式的异步批处理翻译和同步单文档翻译。 文档翻译软件开发工具包(SDK)可帮助你将这些 REST API 功能集成到应用程序中。

先决条件

若要使用文档翻译 SDK,需要:

支持的语言

文档翻译 SDK 支持以下编程语言:

语言和 SDK 版本 客户端库 默认 API 版本
.NET/C# 2.0.0 NuGet 用于 .NET 的 Azure SDK 2024-05-01
Python 2.0.0 PyPI 用于 Python 的 Azure SDK 2026-03-01
Java 2.0.0 Maven Central 适用于 Java 的 Azure SDK 2026-03-01

更改日志和版本历史记录

本部分提供文档翻译功能和功能版本、更改、更新和增强功能的基于版本的说明。

在应用程序中使用文档翻译 SDK

文档翻译 SDK 允许在应用程序中使用和管理翻译服务。 SDK 基于基础文档翻译 REST API 构建,可在编程语言范例中使用。 选择首选编程语言:

1. 安装 SDK 客户端库

dotnet add package Azure.AI.Translation.Document --version 2.0.0
Install-Package Azure.AI.Translation.Document -Version 2.0.0

2. 将 SDK 客户端库导入应用程序

using System;
using Azure.Core;
using Azure.AI.Translation.Document;

3. 对客户端进行身份验证

创建对象实例 DocumentTranslationClient 以与文档翻译 SDK 交互,然后在该客户端对象上调用方法以与服务交互。 DocumentTranslationClient这是使用文档翻译客户端库的主要接口。 它提供同步和异步方法来执行操作。

异步批量翻译

private static readonly string endpoint = "<your-custom-endpoint>";
private static readonly string key = "<your-key>";

DocumentTranslationClient client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(key));

同步单文档翻译

private static readonly string endpoint = "<your-custom-endpoint>";
private static readonly string key = "<your-key>";

SingleDocumentTranslationClient client = new SingleDocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(key));

4. 生成应用程序

异步批量翻译

文档翻译批处理接口需要以下输入:

  1. 将文件上传到 Azure Blob 存储源容器 (sourceUri)。
  2. 提供可将翻译后的文档写入到的目标容器 (targetUri)。
  3. 包括目标语言代码 (targetLanguage)。

Uri sourceUri = new Uri("<your-source-container-url>");
Uri targetUri = new Uri("<your-target-container-url>");
string targetLanguage = "<target-language-code>";

DocumentTranslationInput input = new DocumentTranslationInput(sourceUri, targetUri, targetLanguage);

同步单文档翻译

单文档翻译

帮助选项

Azure Q&AStack Overflow 论坛可供开发人员社区提出和回答有关 Azure 文本翻译和其他服务的问题。 Microsoft 会监视论坛并回复社区尚未回答的问题。

提示

为确保我们看到你的 Microsoft Q&A 问题,请将其标记为 microsoft-translator。 为确保我们看到你的 Stack Overflow 问题,请将其标记为 Azure 翻译器

后续步骤