![]() |
VOOZH | about |
dotnet add package Azure.AI.Translation.Text --version 2.0.0
NuGet\Install-Package Azure.AI.Translation.Text -Version 2.0.0
<PackageReference Include="Azure.AI.Translation.Text" Version="2.0.0" />
<PackageVersion Include="Azure.AI.Translation.Text" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Azure.AI.Translation.Text" />Project file
paket add Azure.AI.Translation.Text --version 2.0.0
#r "nuget: Azure.AI.Translation.Text, 2.0.0"
#:package Azure.AI.Translation.Text@2.0.0
#addin nuget:?package=Azure.AI.Translation.Text&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Azure.AI.Translation.Text&version=2.0.0Install as a Cake Tool
Azure text translation is a cloud-based REST API provided by the Azure Translator service. It utilizes neural machine translation technology to deliver precise, contextually relevant, and semantically accurate real-time text translations across all supported languages.
Use the Text Translation client library for .NET to:
Retrieve the list of languages supported for translation and transliteration operations, as well as LLM models available for translations.
Perform deterministic text translation from a specified source language to a target language, with configurable parameters to ensure precision and maintain contextual integrity.
Execute transliteration by converting text from the original script to an alternative script representation.
Use LLM models to produce translation output variants that are tone-specific and gender-aware.
Source code | API reference documentation | Product documentation
Install the Azure Text Translation client library for .NET with NuGet:
dotnet add package Azure.AI.Translation.Text
This table shows the relationship between SDK versions and supported API versions of the service:
| SDK version | Supported API version of service |
|---|---|
| 1.0.0-beta.1 | 3.0 |
| 1.0.0 | 3.0 |
| 2.0.0-beta.1 | 2025-10-01-preview |
| 2.0.0 | 2026-06-06 |
Interaction with the service using the client library begins with creating an instance of the TextTranslationClient class. You will need an API key or TokenCredential to instantiate a client object. For more information regarding authenticating with Cognitive Services, see Authenticate requests to Translator Service.
You can get the endpoint, API key and Region from the Cognitive Services resource or Translator service resource information in the Azure Portal.
Alternatively, use the Azure CLI snippet below to get the API key from the Translator service resource.
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
TextTranslationClient using an API key and Region credentialOnce you have the value for the API key and Region, create an AzureKeyCredential. This will allow you to
update the API key without creating a new client.
With the value of the endpoint, AzureKeyCredential and a Region, you can create the TextTranslationClient:
string endpoint = "<Text Translator Resource Endpoint>";
string apiKey = "<Text Translator Resource API Key>";
string region = "<Text Translator Azure Region>";
TextTranslationClient client = new TextTranslationClient(new AzureKeyCredential(apiKey), new Uri(endpoint), region);
TextTranslationClient with Microsoft Entra IDClient API key authentication is used in most of the examples, but you can also authenticate with Microsoft Entra ID using the Azure Identity library. To use the DefaultAzureCredential provider shown below, install the Azure.Identity package:
dotnet add package Azure.Identity
Create a custom subdomain for your resource in order to use this type of authentication. Use this value for the endpoint variable for Text Translator Custom Endpoint.
You will also need to register a new Microsoft Entra application and grant access to your Translator resource by assigning the "Cognitive Services User" role to your service principal. Additional information about Microsoft Entra authentication is available here.
Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET. The DefaultAzureCredential constructor uses these variables to create your credentials.
string endpoint = "<Text Translator Custom Endpoint>";
DefaultAzureCredential credential = new DefaultAzureCredential();
TextTranslationClient client = new TextTranslationClient(credential, new Uri(endpoint));
TextTranslationClientA TextTranslationClient is the primary interface for developers using the Text Translation client library. It provides both synchronous and asynchronous operations to access a specific use of text translator, such as get supported languages detection or text translation.
A TranslateInputItem is a single unit of input to be processed by the translation models in the Translator service. Each TranslateInputItem defines both the input string to translate and the output specifications for the translation. Operations on TextTranslationClient may take a single TranslateInputItem or a collection of TranslateInputItem objects.
For text element length limits, maximum requests size, and supported text encoding see here.
Return values, such as Response<IReadOnlyList<TranslatedTextItem>>, is the result of a Text Translation operation. It contains an array with one TranslatedTextItem for each input TranslateInputItem. An operation's return value also may optionally include information about the input text element (for example detected language).
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
The following section provides several code snippets using the client created above, and covers the main features present in this client library. Although the snippets below make use of synchronous service calls, keep in mind that the Azure.AI.Translation.Text package supports both synchronous and asynchronous APIs.
Gets the set of languages currently supported by other operations of the Translator.
try
{
Response<GetSupportedLanguagesResult> response = client.GetSupportedLanguages(cancellationToken: CancellationToken.None);
GetSupportedLanguagesResult languages = response.Value;
Console.WriteLine($"Number of supported languages for translate operations: {languages.Translation.Count}.");
}
catch (RequestFailedException exception)
{
Console.WriteLine($"Error Code: {exception.ErrorCode}");
Console.WriteLine($"Message: {exception.Message}");
}
For samples on using the languages endpoint refer to more samples here.
Please refer to the service documentation for a conceptual discussion of languages.
The simplest use of the Translate method is to invoke it with a single target language and one input string.
try
{
string targetLanguage = "cs";
string inputText = "This is a test.";
Response<IReadOnlyList<TranslatedTextItem>> response = client.Translate(targetLanguage, inputText);
IReadOnlyList<TranslatedTextItem> translations = response.Value;
TranslatedTextItem translation = translations.FirstOrDefault();
Console.WriteLine($"Detected languages of the input text: {translation?.DetectedLanguage?.Language} with score: {translation?.DetectedLanguage?.Score}.");
Console.WriteLine($"Text was translated to: '{translation?.Translations?.FirstOrDefault().Language}' and the result is: '{translation?.Translations?.FirstOrDefault()?.Text}'.");
}
catch (RequestFailedException exception)
{
Console.WriteLine($"Error Code: {exception.ErrorCode}");
Console.WriteLine($"Message: {exception.Message}");
}
For samples on using the translate endpoint refer to more samples here.
Please refer to the service documentation for a conceptual discussion of translate.
Converts characters or letters of a source language to the corresponding characters or letters of a target language.
try
{
string language = "zh-Hans";
string fromScript = "Hans";
string toScript = "Latn";
string inputText = "这是个测试。";
Response<IReadOnlyList<TransliteratedText>> response = client.Transliterate(language, fromScript, toScript, inputText);
IReadOnlyList<TransliteratedText> transliterations = response.Value;
TransliteratedText transliteration = transliterations.FirstOrDefault();
Console.WriteLine($"Input text was transliterated to '{transliteration?.Script}' script. Transliterated text: '{transliteration?.Text}'.");
}
catch (RequestFailedException exception)
{
Console.WriteLine($"Error Code: {exception.ErrorCode}");
Console.WriteLine($"Message: {exception.Message}");
}
For samples on using the transliterate endpoint refer to more samples here.
Please refer to the service documentation for a conceptual discussion of transliterate.
When you interact with the Translator Service using the Text Translation client library, errors returned by the Translator service correspond to the same HTTP status codes returned for REST API requests.
For example, if you submit a translation request without a target translate language, a 400 error is returned, indicating "Bad Request".
try
{
var translation = client.Translate("", "This is a Test");
}
catch (RequestFailedException e)
{
Console.WriteLine(e.ToString());
}
You will notice that additional information is logged, like the client request ID of the operation.
Message:
Azure.RequestFailedException: Service request failed.
Status: 400 (Bad Request)
Content:
{"error":{"code":400036,"message":"The target language is not valid."}}
Headers:
X-RequestId: REDACTED
Access-Control-Expose-Headers: REDACTED
X-Content-Type-Options: REDACTED
Strict-Transport-Security: REDACTED
Date: Mon, 27 Feb 2023 23:31:37 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 71
The simplest way to see the logs is to enable the console logging. To create an Azure SDK log listener that outputs messages to console use AzureEventSourceListener.CreateConsoleLogger method.
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
To learn more about other logging mechanisms see here.
Samples showing how to use this client library are available in this GitHub repository. Samples are provided for each main functional area, and for each area, samples are provided in both sync and async mode.
See the CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Azure.AI.Translation.Text:
| Package | Downloads |
|---|---|
|
HexaEightGPTMiddleware
Control An AI Assistant like CHATGPT using this Library. Integrate This Library With HexaEight Middleware to create API that produce controlled AI responses |
|
|
BootstrapBlazor.AzureTranslator
Bootstrap UI components extensions of Azure Translator |
|
|
LocalizationProvider.Translator.Azure
Azure Cognitive services implementation for auto-translator feature. |
|
|
DevExpress.AIIntegration.Azure.Translation
Target Platform/Framework: Cross-Platform DevExpress Product Libraries Used: DevExpress AI-powered Extensions for OpenAI, Azure, Ollama, Semantic Kernel (https://www.devexpress.com/ai) Available in the following DevExpress Subscription(s): Universal, DXperience, WinForms, ASP.NET & Blazor (includes DevExtreme), WPF, Reporting, Office File API |
|
|
PowerPortalsPro.Web.Server
Server-side services for PowerPortalsPro including Dataverse data access, security enforcement, interceptor execution, localization loading, and identity page defaults. |
Showing the top 4 popular GitHub repositories that depend on Azure.AI.Translation.Text:
| Repository | Stars |
|---|---|
|
Richasy/FantasyCopilot
A new-age AI desktop tool
|
|
|
valdisiljuconoks/LocalizationProvider
Database driven localization provider for .NET applications
|
|
|
Azure/azure-sdk-tools
Tools repository leveraged by the Azure SDK team.
|
|
|
Richasy/RichasyAssistant
个人助理
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 5,285 | 5/29/2026 |
| 2.0.0-beta.1 | 4,213 | 1/8/2026 |
| 1.0.0 | 1,368,090 | 5/21/2024 |
| 1.0.0-beta.1 | 271,839 | 4/18/2023 |