Translator is a cloud-based machine translation service you can use to translate text in near real-time through a simple REST API call. The service uses modern neural machine translation technology and offers statistical machine translation technology.
For more information, refer to the Microsoft Documentation.
In this post, we will call three APIs. The first one is to get the list of all the Languages supported by the Translator. The second will be to translate text and the third one will detect language.
Prerequisites
- Valid Azure Subscription – Create a free Azure account here.
- Create Translator Resource in Azure Portal
- Postman
Get the Supported Language List
Open Postman, create a new collection or use an existing one. Create a new GET request inside the collection. Name it as Languages Supported
.
Give the following URL to get the list of all supported languages with their codes.
https://api.cognitive.microsofttranslator.com/languages?api-version=3.0&scope=translation
This is a GET request which does not require any authentication. The Params will automatically get populated from the URL. Finally, click on Send.

Translate Text
Go to your Azure Translator resource. Click on Keys and Endpoint under Resource Management. Copy the secret key which will be used to authenticate the translate text API.

Open Postman, create a new POST request inside the collection and name it Translate Text
.

Give the following URL to translate the text to Italian
language. it
is the language code for Italian.
https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=it
This request will create two params. One is the api-version
and another is to
. The to
value should contain the language code you want to translate the text to.

Go to headers and enter the following header keys as below.
- Ocp-Apim-Subscription-Key
- Content-Type
- Ocp-Apim-Subscription-Region (Use this key only if your region is not global)
Since my region is global, I will not use the region key. You can find the region in Keys and Endpoint under Resource Management in Azure.

Enter the secret key that you copied from the Azure Portal as value for the Ocp-Apim-Subscription-Key. The value of Content-Type
is application/json
.
Next, go to the Body and give the text as a JSON object.
[{"Text":"Hello JD, how are you?"}]

Finally, send the request. This API does two things, one is to detect the language used in the body and another is to translate the text to the language you defined in the params.

Detect Language
Create a new POST request for Detect Language.

Enter the following URL for detecting languages.
https://api.cognitive.microsofttranslator.com/detect?api-version=3.0
The Header remains the same as we saw in the Translate Text API. Change the body to give a text.
[
{ "Text": "Ciao JD, come stai?" }
]
I am using the output from the Translate Text. Detect language should show me output as Italian.

This completes our call to the Translator APIs. This will be a prerequisite to the Language Translator bot using Azure Translator API.