文档翻译 SDK

文档翻译是 Azure AI Translator 服务的基于云的 REST API 功能。 文档翻译 API 支持异步地将整个文档从源语言快速准确地翻译为目标语言,适用于支持的语言和各种文件格式。 文档翻译软件开发工具包(SDK)是一组库和工具,可用于将文档翻译 REST API 功能轻松集成到应用程序中。

支持的语言

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

语言 → SDK 版本 客户端库 支持的 API 版本
🆕 .NET/C# → 2.0.0 NuGet 用于 .NET 的 Azure SDK
🆕 Python → 1.0.0 PyPi 用于 Python 的 Azure SDK

更改日志和版本历史记录

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

在应用程序中使用文档翻译 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(apiKey));

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 AI Translator

后续步骤