Guide to using Azure Translator to detect language, translate text into multiple languages, and transliterate scripts with REST examples and a Python SDK sample.
This guide demonstrates how to detect language, perform translations, and transliterate text using Azure’s Translator service. You’ll see REST examples (detect, translate, transliterate) and a concise Python SDK example using the azure-ai-translation-text package.
Overview
Detect: Identify the language of a given piece of text and learn whether translation or transliteration is supported.
Translate: Convert text between languages (one or more target languages).
Transliterate: Convert text from one script to another (e.g., Arabic script → Latin script).
SDK option: Use the Azure Python SDK for integration with fewer manual HTTP calls.
Detect (REST)
Use the detect endpoint to identify the language and whether translation/transliteration is supported for the input text.Example REST request (detect):
Copy
POST https://api.cognitive.microsofttranslator.com/detect?api-version=3.0Content-Type: application/jsonOcp-Apim-Subscription-Key: <your-key>[ { "Text": "مرحبا" }]
Use the returned ISO language code (for example, “ar”) to decide the next action — translate to other languages or transliterate to another script.Translate (REST)
Translate the detected source language into one or more target languages by calling the translate endpoint and specifying target languages as query parameters.Example REST request (translate):
Copy
POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=ar&to=en&to=fr"Content-Type: application/jsonOcp-Apim-Subscription-Key: <your-key>[ { "Text": "مرحبا" }]
Transliteration (REST)
Transliteration converts text from one writing system (script) into another. Provide the source language and script and the desired target script.Example REST request (transliterate):
Copy
POST "https://api.cognitive.microsofttranslator.com/transliterate?api-version=3.0&language=ar&fromScript=Arab&toScript=Latn"Content-Type: application/jsonOcp-Apim-Subscription-Key: <your-key>[ { "Text": "مرحبا" }]
Example response (transliterate):
Copy
[ { "script": "Latn", "text": "Marhaba" }]
Translate vs. Transliterate — quick comparison
Feature
Translate
Transliterate
Purpose
Convert meaning across languages
Convert characters across scripts
Input
Text in any supported language
Text and source script
Output
Target-language text (semantic translation)
Same-language text in different script
Example
”مرحبا” → “Hello"
"مرحبا” (Arab) → “Marhaba” (Latn)
Python SDK (azure-ai-translation-text)
You can perform detection, translation, and transliteration using the Azure Python SDK. Install and verify the package:
Copy
pip3 install azure-ai-translation-textpip3 show azure-ai-translation-text
Example installation output (trimmed):
Copy
Name: azure-ai-translation-textVersion: 1.0.1Summary: Microsoft Azure AI Translation Text Client Library for PythonHome-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdkAuthor: Microsoft CorporationLicense: MITRequires: azure-core, isodate, typing-extensions
Complete Python example
This example detects language (if returned by the service), translates a Korean sentence into English and French, and transliterates it into the Latin script.
Copy
# app.pyfrom azure.core.credentials import AzureKeyCredentialfrom azure.ai.translation.text import TextTranslationClient# Replace with your valuesendpoint = "https://<your-resource-name>.cognitiveservices.azure.com/"key = "<your-key>"# Initialize clientcredential = AzureKeyCredential(key)client = TextTranslationClient(endpoint=endpoint, credential=credential)# Text to translate/transliterate (Korean)input_text = "좋은 아침입니다. 잘 지내세요?"body = [{"text": input_text}]# Call the translate method (translate to English and French)# Depending on SDK version the parameter name may be `to` or `to_language`.# Here we use `to_language` to pass multiple target languages as an array.response = client.translate(body=body, to_language=["en", "fr"])# Call the transliterate method (Korean script to Latin)transliteration_response = client.transliterate( body=body, language="ko", from_script="Kore", to_script="Latn")# Extract transliteration texttransliteration_text = transliteration_response[0].text# Print detected language, translations and transliterationdetected = response[0].detectedLanguage if hasattr(response[0], "detectedLanguage") else response[0].get("detectedLanguage")print(f"Detected Language: {detected['language']} (Score: {detected['score']})")print("\n=== Translation & Transliteration Output ===")translations = response[0].translations if hasattr(response[0], "translations") else response[0].get("translations", [])for t in translations: lang = t.to.upper() if hasattr(t, "to") else t.get("to", "").upper() text = t.text if hasattr(t, "text") else t.get("text", "") print(f"\n- {lang}: {text}")print(f"\nTransliteration (Latin Script): {transliteration_text}")
Example console output after running the script:
Copy
Detected Language: ko (Score: 1.0)=== Translation & Transliteration Output ===- EN: Good morning. How are you?- FR: Bonjour. Comment vas-tu?Transliteration (Latin Script): joheun achimnida. jal jinaeseyo?
Credentials and resource types
You can use either:
A Translation resource, or
An Azure AI Multi-Service (Cognitive Services) resource.
Each resource type provides different endpoint and key formats. Use the credentials for the resource you provisioned when initializing the SDK or sending REST requests.
If you need consistent, domain-specific translations (for example, standardized product names or industry terminology), consider custom glossaries or training a custom translator model. Pre-built models are great for general-purpose translation, but custom models and glossaries let you control vocabulary and translation behavior.