> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Translator Service

> 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.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/MVK09m96KxI8SuM5/images/AI-102-Microsoft-Certified-Azure-AI-Engineer-Associate/Translating-Text/Working-with-Translator-Service/kodekloud-translator-service-slide.jpg?fit=max&auto=format&n=MVK09m96KxI8SuM5&q=85&s=98b244745c07858f54199baad50c0307" alt="A dark-themed slide showing the KodeKloud logo at the top and the centered title &#x22;Working with Translator Service.&#x22; Small copyright text &#x22;© Copyright KodeKloud&#x22; appears in the lower-left corner." width="1920" height="1080" data-path="images/AI-102-Microsoft-Certified-Azure-AI-Engineer-Associate/Translating-Text/Working-with-Translator-Service/kodekloud-translator-service-slide.jpg" />
</Frame>

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

* [Translator Text API documentation](https://learn.microsoft.com/azure/cognitive-services/translator/)
* [Azure SDK for Python — Translation client](https://learn.microsoft.com/azure/developer/python/)

API endpoint summary

| Operation     | Endpoint (path) | Key query parameters                        |
| ------------- | --------------- | ------------------------------------------- |
| Detect        | /detect         | api-version                                 |
| Translate     | /translate      | api-version, from, to (repeatable)          |
| Transliterate | /transliterate  | api-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):

```http theme={null}
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):

```json theme={null}
[
  {
    "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):

```http theme={null}
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):

```json theme={null}
[
  {
    "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):

```http theme={null}
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):

```json theme={null}
[
  {
    "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:

```bash theme={null}
pip3 install azure-ai-translation-text
pip3 show azure-ai-translation-text
```

Example installation output (trimmed):

```text theme={null}
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.

```python theme={null}
# 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:

```text theme={null}
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.

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

Additional resources

* [Translator Text API — Microsoft Learn](https://learn.microsoft.com/azure/cognitive-services/translator/)
* [Azure SDK for Python — Translation client reference](https://learn.microsoft.com/azure/developer/python/)

Use these links to explore supported languages, scripts, and advanced customization options such as glossaries and custom models.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/ai-102-microsoft-certified-azure-ai-engineer-associate/module/5f79b307-e7de-415a-9d8d-82499e075c20/lesson/9e2b2754-329d-4593-b946-41f8faf160fd" />
</CardGroup>
