Microsoft Translator API Example

This Azure tutorial will discuss Azure Cognitive Services Translator Text API Examples.

In this article, We will discuss how to translate text into multiple languages, Translator Text API with ASP.NET core and C#. It is going to be an interesting article. As part of this article, we will perform the below steps

  • Create a Translator Text API in Azure Portal.
  • Create an ASP.NET Core application using Visual Studio 2019 and the Translator Text API Key.

Let’s discuss the Prerequisites needed for implementing the functionality here.

Prerequisites

Assuming you have all the prerequisites, Let’s start creating the Microsoft Translator Text API in the Azure Portal and discuss an Azure Cognitive Services Translator Text API Example.

Create a Microsoft Translator Text API in Azure Portal

The first step is creating an Azure Translator Text API in Azure Portal by following the below steps.

  1. Log in to the Azure Portal (https://portal.azure.com/)
  2. Once you log in to the Azure Portal, search for the Translator and then click on the search result Translator under the Marketplace as highlighted below.
azure translation api example

Or, for the same option, you can click on the + Create a resource from the left navigation on the Home page. On the New window, search for the Translator and then click on the search result Translator.

microsoft translator api sample c#

3. The next step is to click the Create button in the Translator window, as shown below.

azure language translator

4. Now, on the Create Translator window, Provide the below details

  • Subscription: You must Choose a valid subscription you want to use here.
  • Resource Group: You can choose your existing Resource Group here. If you haven’t had an existing Resource Group created, create a new Resource Group by clicking on the Create new link.
  • Resource Region: Select a Region for your Azure Resource.
  • Name: You must provide a unique name for your Azure Cognitive Services Translator Text API.
  • Pricing tier: You can select the Pricing tier based on your business needs. You can click on the View full pricing details link to verify the pricing details for your reference. For the Demo purpose, you can choose the Free F0 tier. For this tier, you can get up to 2M number of characters translated per month free of cost.

After providing all the above details, click on the Review + Create button as highlighted below.

microsoft translator api

5. The next window will validate all the information you entered in the above window and then show you the Validation Passed message. You can see the Create button is enabled, as shown below. Now, you can verify the details you entered again for a safer side and then click on the Create button to create the Microsoft Translator Text API.

azure translator

Once you click on the Create button, it will take a few seconds to create all the components. As you can see below, the deployment was completed successfully without any issues. Click the Go to Resource button to see the Microsoft Translator Text API you created just now.

azure translator api

Below is the Microsoft Translator Text API that we created just now.

azure translation api languages

So, our Azure Cognitive Services Translator Text API is ready now. The next step is to copy the value of the Key1 of the Azure Cognitive Services Translator Text API. To copy the key1 value, click on the Keys and Endpoint option from the left navigation on the Cognitive Services window. You can click the Copy button to copy the Key1 or Key2 values as highlighted below. Copy the key value and keep it in a notepad that we will use in the Asp.Net core application code in Visual Studio.

azure translation api

So, we have created the Azure Cognitive Services Translator Text API in Azure Portal and copied the key value of the Transla