Select Page

Following our previous post about Azure AI Translator, this post will show how to translate text between a source and target language using C#.

About Azure AI Translator

Microsoft Azure AI Translator offers translation services like language detection and translation for over 90 languages using a single API endpoint.

The process to use Azure AI Translator starts with the provisioning of an Azure AI Service (Multi-service or Translator) and using an SDK or Azure REST API to use the service.

Azure AI Translator offers two core services: Language detection and Language translations. To use the detection service, we need to send a text in a key-value pair format with the language that we would like to detect.

The translation service uses two parameters, From and To, that indicate the source (From) and target (To) languages. We can also count the number of characters in a translated sentence using built-in functions that come with the API.

How to Translate Text Using Azure AI Translator and .NET

The following C# program uses the Azure AI Translator REST API endpoint to translate text (Source to Target). To get started, create a C# project and install the Translation library.

In your .NET project, create a appsettings.json file with the details of your access key and region.

In your Programs.cs file, add the following code.