Skip to main content
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.
A dark-themed slide showing the KodeKloud logo at the top and the centered title "Working with Translator Service." Small copyright text "© Copyright KodeKloud" appears in the lower-left corner.
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.
Quick reference links API endpoint summary
OperationEndpoint (path)Key query parameters
Detect/detectapi-version
Translate/translateapi-version, from, to (repeatable)
Transliterate/transliterateapi-version, language, fromScript, toScript
Detect (REST) Use the detect endpoint to identify the language and whether translation/transliteration is supported for the input text. Example REST request (detect):
POST https://api.cognitive.microsofttranslator.com/detect?api-version=3.0
Content-Type: application/json
Ocp-Apim-Subscription-Key: <your-key>

[
  { "Text": "مرحبا" }
]
Example response (detect):
[
  {
    "language": "ar",
    "score": 1.0,
    "isTranslationSupported": true,
    "isTransliterationSupported": true
  }
]
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):
POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=ar&to=en&to=fr"
Content-Type: application/json
Ocp-Apim-Subscription-Key: <your-key>

[
  { "Text": "مرحبا" }
]
Example response (translate):
[
  {
    "translations": [
      { "text": "Hello", "to": "en" },
      { "text": "Bonjour", "to": "fr" }
    ]
  }
]
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):
POST "https://api.cognitive.microsofttranslator.com/transliterate?api-version=3.0&language=ar&fromScript=Arab&toScript=Latn"
Content-Type: application/json
Ocp-Apim-Subscription-Key: <your-key>

[
  { "Text": "مرحبا" }
]
Example response (transliterate):
[
  {
    "script": "Latn",
    "text": "Marhaba"
  }
]
Translate vs. Transliterate — quick comparison
FeatureTranslateTransliterate
PurposeConvert meaning across languagesConvert characters across scripts
InputText in any supported languageText and source script
OutputTarget-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:
pip3 install azure-ai-translation-text
pip3 show azure-ai-translation-text
Example installation output (trimmed):
Name: azure-ai-translation-text
Version: 1.0.1
Summary: Microsoft Azure AI Translation Text Client Library for Python
Home-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk
Author: Microsoft Corporation
License: MIT
Requires: 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.
# app.py
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.text import TextTranslationClient

# Replace with your values
endpoint = "https://<your-resource-name>.cognitiveservices.azure.com/"
key = "<your-key>"

# Initialize client
credential = 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 text
transliteration_text = transliteration_response[0].text

# Print detected language, translations and transliteration
detected = 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:
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.
Additional resources Use these links to explore supported languages, scripts, and advanced customization options such as glossaries and custom models.

Watch Video