Azure AI Translation Text Py
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Software development
- MIT
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The azure-ai-translation-text-py skill provides a Python client library for interacting with the Azure AI Translator service. It enables developers to perform real-time text translation, language detection, transliteration, and dictionary lookups within their applications. The library supports both synchronous and asynchronous operations and provides mechanisms for secure authentication using Azure identity credentials.
What it does
- Translates text into multiple languages simultaneously.
- Detects the source language of provided text.
- Converts text between different scripts via transliteration.
- Performs dictionary lookups for definitions and alternate translations.
- Identifies sentence boundaries within text.
- Retrieves lists of supported languages for translation, transliteration, and dictionary features.
When to use it
- When building applications that require multi-language support.
- When you need to detect the language of user-provided content.
- When integrating dictionary or transliteration features into a software product.
- When you need to process text translation tasks in a Python-based environment.
Advantages
- Supports both sync and async client patterns.
- Integrates with Azure identity management for secure authentication.
- Allows batch processing of multiple text inputs in a single request.
- Provides granular control over translation options like profanity handling and text formatting.
Usage examples
- “Translate 'Hello, world!' into Spanish using the Azure Translator SDK.”
- The agent uses the TextTranslationClient to send the text to the translation service and returns the Spanish translation.
- “Detect the language of the text 'Hola, como estas?'”
- The agent processes the text through the translation client and identifies the language as Spanish with a confidence score.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/microsoft/azure-ai-translation-text-py/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-ai-translation-text-py.zip -d .agents/skills
Documentation by Microsoft
Azure AI Text Translation SDK for Python
Client library for Azure AI Translator text translation service for real-time text translation, transliteration, and language operations.
Installation
pip install azure-ai-translation-textEnvironment Variables
AZURE_TRANSLATOR_ENDPOINT=https://<resource>.cognitiveservices.azure.com # Required for Entra ID auth (must be a custom subdomain endpoint)
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
# Only required for the legacy API-key auth path below:
AZURE_TRANSLATOR_KEY=<your-api-key>
AZURE_TRANSLATOR_REGION=<your-region> # e.g., eastus, westus2; required when authenticating with a key against the global endpointAuthentication & Lifecycle
🔑 Two rules apply to every code sample below:
Prefer
DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
Local dev:
DefaultAzureCredentialworks as-is.Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
Sync:
with <Client>(...) as client:Async:
async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
import os
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.ai.translation.text import TextTranslationClient
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
with TextTranslationClient(
endpoint=os.environ["AZURE_TRANSLATOR_ENDPOINT"],
credential=credential,
) as client:
result = client.translate(body=["Hello, world!"], to=["es"])Legacy: API Key (existing keyed deployments)
New code should use DefaultAzureCredential above. The Translator service has two specifics that make API-key auth still common in existing deployments:
Token-credential auth requires a custom subdomain endpoint (
https://<resource>.cognitiveservices.azure.com). If you only have the global endpoint (https://api.cognitive.microsofttranslator.com), you must either provision a custom subdomain or stay on the key-based path until you do.Key + region is the canonical setup against the global endpoint. The region is sent as the
Ocp-Apim-Subscription-Regionheader and is required whenever you use a multi-service or global Translator key.
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.text import TextTranslationClient
# Key + region against the global endpoint (most common keyed setup)
with TextTranslationClient(
credential=AzureKeyCredential(os.environ["AZURE_TRANSLATOR_KEY"]),
region=os.environ["AZURE_TRANSLATOR_REGION"],
) as client:
result = client.translate(body=["Hello, world!"], to=["es"])
# Key against a custom subdomain endpoint (no region required)
with TextTranslationClient(
endpoint=os.environ["AZURE_TRANSLATOR_ENDPOINT"],
credential=AzureKeyCredential(os.environ["AZURE_TRANSLATOR_KEY"]),
) as client:
result = client.translate(body=["Hello, world!"], to=["es"])Basic Translation
# Translate to a single language
result = client.translate(
body=["Hello, how are you?", "Welcome to Azure!"],
to=["es"] # Spanish
)
for item in result:
for translation in item.translations:
print(f"Translated: {translation.text}")
print(f"Target language: {translation.to}")Translate to Multiple Languages
result = client.translate(
body=["Hello, world!"],
to=["es", "fr", "de", "ja"] # Spanish, French, German, Japanese
)
for item in result:
print(f"Source: {item.detected_language.language if item.detected_language else 'unknown'}")
for translation in item.translations:
print(f" {translation.to}: {translation.text}")Specify Source Language
result = client.translate(
body=["Bonjour le monde"],
from_parameter="fr", # Source is French
to=["en", "es"]
)Language Detection
result = client.translate(
body=["Hola, como estas?"],
to=["en"]
)
for item in result:
if item.detected_language:
print(f"Detected language: {item.detected_language.language}")
print(f"Confidence: {item.detected_language.score:.2f}")Transliteration
Convert text from one script to another:
result = client.transliterate(
body=["konnichiwa"],
language="ja",
from_script="Latn", # From Latin script
to_script="Jpan" # To Japanese script
)
for item in result:
print(f"Transliterated: {item.text}")
print(f"Script: {item.script}")Dictionary Lookup
Find alternate translations and definitions:
result = client.lookup_dictionary_entries(
body=["fly"],
from_parameter="en",
to="es"
)
for item in result:
print(f"Source: {item.normalized_source} ({item.display_source})")
for translation in item.translations:
print(f" Translation: {translation.normalized_target}")
print(f" Part of speech: {translation.pos_tag}")
print(f" Confidence: {translation.confidence:.2f}")Dictionary Examples
Get usage examples for translations:
from azure.ai.translation.text.models import DictionaryExampleTextItem
result = client.lookup_dictionary_examples(
body=[DictionaryExampleTextItem(text="fly", translation="volar")],
from_parameter="en",
to="es"
)
for item in result:
for example in item.examples:
print(f"Source: {example.source_prefix}{example.source_term}{example.source_suffix}")
print(f"Target: {example.target_prefix}{example.target_term}{example.target_suffix}")Get Supported Languages
# Get all supported languages
languages = client.get_supported_languages()
# Translation languages
print("Translation languages:")
for code, lang in languages.translation.items():
print(f" {code}: {lang.name} ({lang.native_name})")
# Transliteration languages
print("\nTransliteration languages:")
for code, lang in languages.transliteration.items():
print(f" {code}: {lang.name}")
for script in lang.scripts:
print(f" {script.code} -> {[t.code for t in script.to_scripts]}")
# Dictionary languages
print("\nDictionary languages:")
for code, lang in languages.dictionary.items():
print(f" {code}: {lang.name}")Break Sentence
Identify sentence boundaries:
result = client.find_sentence_boundaries(
body=["Hello! How are you? I hope you are well."],
language="en"
)
for item in result:
print(f"Sentence lengths: {item.sent_len}")Translation Options
result = client.translate(
body=["Hello, world!"],
to=["de"],
text_type="html", # "plain" or "html"
profanity_action="Marked", # "NoAction", "Deleted", "Marked"
profanity_marker="Asterisk", # "Asterisk", "Tag"
include_alignment=True, # Include word alignment
include_sentence_length=True # Include sentence boundaries
)
for item in result:
translation = item.translations[0]
print(f"Translated: {translation.text}")
if translation.alignment:
print(f"Alignment: {translation.alignment.proj}")
if translation.sent_len:
print(f"Sentence lengths: {translation.sent_len.src_sent_len}")Async Client
from azure.ai.translation.text.aio import TextTranslationClient
from azure.identity.aio import DefaultAzureCredential
async def translate_text():
async with DefaultAzureCredential() as credential:
async with TextTranslationClient(
credential=credential,
endpoint=endpoint,
) as client:
result = await client.translate(
body=["Hello, world!"],
to=["es"]
)
print(result[0].translations[0].text)Client Methods
| Method | Description |
|---|---|
translate | Translate text to one or more languages |
transliterate | Convert text between scripts |
detect | Detect language of text |
find_sentence_boundaries | Identify sentence boundaries |
lookup_dictionary_entries | Dictionary lookup for translations |
lookup_dictionary_examples | Get usage examples |
get_supported_languages | List supported languages |
Best Practices
Pick sync OR async and stay consistent. Do not mix
azure.xxxsync clients withazure.xxx.aioasync clients in the same call path. Choose one mode per module.Always use context managers for clients and async credentials. Wrap every client in
with Client(...) as client:(sync) orasync with Client(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up.Batch translations — Send multiple texts in one request (up to 100)
Specify source language when known to improve accuracy
Use async client for high-throughput scenarios
Cache language list — Supported languages don't change frequently
Handle profanity appropriately for your application
Use html text_type when translating HTML content
Include alignment for applications needing word mapping
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
Files
- ATTRIBUTION.mdAdded by AutoGineer995 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md10.6 KiB
- references/capabilities.md2.2 KiB
- references/non-hero-scenarios.md4.6 KiB
references/capabilities.md
azure-ai-translation-text-py capability coverage
SDK/package: azure-ai-translation-text
This index maps hero scenarios in SKILL.md and links non-hero scenarios documented in dedicated reference files.
Hero scenarios covered in SKILL.md
Basic TranslationTranslate to Multiple LanguagesSpecify Source LanguageLanguage Detection
Non-hero scenarios
Transliteration: Convert text from one script to another:
See:non-hero-scenarios.md#transliterationDictionary Lookup: Find alternate translations and definitions:
See:non-hero-scenarios.md#dictionary-lookupDictionary Examples: Get usage examples for translations:
See:non-hero-scenarios.md#dictionary-examplesGet Supported Languages: Dedicated example and implementation notes.
See:non-hero-scenarios.md#get-supported-languagesBreak Sentence: Identify sentence boundaries:
See:non-hero-scenarios.md#break-sentenceTranslation Options: Dedicated example and implementation notes.
See:non-hero-scenarios.md#translation-optionsAsync Client: Dedicated example and implementation notes.
See:non-hero-scenarios.md#async-clientClient Methods: | Method | Description |
See:non-hero-scenarios.md#client-methods
Related deep-dive references
non-hero-scenarios.md: Dedicated non-hero examples and implementation notes.
API breadth checklist
Verify client/auth mode for the environment before coding.
Confirm operation-group/method names against current Microsoft Learn API reference.
For Python SDKs with both sync and async clients, document both forms without a blanket preference.
Include cleanup/delete paths for created resources in examples.
Prefer idempotent create/update operations where available.
Validate paging/LRO/error-handling patterns for production paths.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an API key, Needs Python
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-python/skills/azure-ai-translation-text-py · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft or Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-ai-translation-text-py.zip