Add this skill
npx mdskills install sickn33/azure-ai-translation-text-pyComprehensive SDK reference with extensive examples but lacks agent-specific instructions
1---2name: azure-ai-translation-text-py3description: |4 Azure AI Text Translation SDK for real-time text translation, transliteration, language detection, and dictionary lookup. Use for translating text content in applications.5 Triggers: "text translation", "translator", "translate text", "transliterate", "TextTranslationClient".6package: azure-ai-translation-text7---89# Azure AI Text Translation SDK for Python1011Client library for Azure AI Translator text translation service for real-time text translation, transliteration, and language operations.1213## Installation1415```bash16pip install azure-ai-translation-text17```1819## Environment Variables2021```bash22AZURE_TRANSLATOR_KEY=<your-api-key>23AZURE_TRANSLATOR_REGION=<your-region> # e.g., eastus, westus224# Or use custom endpoint25AZURE_TRANSLATOR_ENDPOINT=https://<resource>.cognitiveservices.azure.com26```2728## Authentication2930### API Key with Region3132```python33import os34from azure.ai.translation.text import TextTranslationClient35from azure.core.credentials import AzureKeyCredential3637key = os.environ["AZURE_TRANSLATOR_KEY"]38region = os.environ["AZURE_TRANSLATOR_REGION"]3940# Create credential with region41credential = AzureKeyCredential(key)42client = TextTranslationClient(credential=credential, region=region)43```4445### API Key with Custom Endpoint4647```python48endpoint = os.environ["AZURE_TRANSLATOR_ENDPOINT"]4950client = TextTranslationClient(51 credential=AzureKeyCredential(key),52 endpoint=endpoint53)54```5556### Entra ID (Recommended)5758```python59from azure.ai.translation.text import TextTranslationClient60from azure.identity import DefaultAzureCredential6162client = TextTranslationClient(63 credential=DefaultAzureCredential(),64 endpoint=os.environ["AZURE_TRANSLATOR_ENDPOINT"]65)66```6768## Basic Translation6970```python71# Translate to a single language72result = client.translate(73 body=["Hello, how are you?", "Welcome to Azure!"],74 to=["es"] # Spanish75)7677for item in result:78 for translation in item.translations:79 print(f"Translated: {translation.text}")80 print(f"Target language: {translation.to}")81```8283## Translate to Multiple Languages8485```python86result = client.translate(87 body=["Hello, world!"],88 to=["es", "fr", "de", "ja"] # Spanish, French, German, Japanese89)9091for item in result:92 print(f"Source: {item.detected_language.language if item.detected_language else 'unknown'}")93 for translation in item.translations:94 print(f" {translation.to}: {translation.text}")95```9697## Specify Source Language9899```python100result = client.translate(101 body=["Bonjour le monde"],102 from_parameter="fr", # Source is French103 to=["en", "es"]104)105```106107## Language Detection108109```python110result = client.translate(111 body=["Hola, como estas?"],112 to=["en"]113)114115for item in result:116 if item.detected_language:117 print(f"Detected language: {item.detected_language.language}")118 print(f"Confidence: {item.detected_language.score:.2f}")119```120121## Transliteration122123Convert text from one script to another:124125```python126result = client.transliterate(127 body=["konnichiwa"],128 language="ja",129 from_script="Latn", # From Latin script130 to_script="Jpan" # To Japanese script131)132133for item in result:134 print(f"Transliterated: {item.text}")135 print(f"Script: {item.script}")136```137138## Dictionary Lookup139140Find alternate translations and definitions:141142```python143result = client.lookup_dictionary_entries(144 body=["fly"],145 from_parameter="en",146 to="es"147)148149for item in result:150 print(f"Source: {item.normalized_source} ({item.display_source})")151 for translation in item.translations:152 print(f" Translation: {translation.normalized_target}")153 print(f" Part of speech: {translation.pos_tag}")154 print(f" Confidence: {translation.confidence:.2f}")155```156157## Dictionary Examples158159Get usage examples for translations:160161```python162from azure.ai.translation.text.models import DictionaryExampleTextItem163164result = client.lookup_dictionary_examples(165 body=[DictionaryExampleTextItem(text="fly", translation="volar")],166 from_parameter="en",167 to="es"168)169170for item in result:171 for example in item.examples:172 print(f"Source: {example.source_prefix}{example.source_term}{example.source_suffix}")173 print(f"Target: {example.target_prefix}{example.target_term}{example.target_suffix}")174```175176## Get Supported Languages177178```python179# Get all supported languages180languages = client.get_supported_languages()181182# Translation languages183print("Translation languages:")184for code, lang in languages.translation.items():185 print(f" {code}: {lang.name} ({lang.native_name})")186187# Transliteration languages188print("\nTransliteration languages:")189for code, lang in languages.transliteration.items():190 print(f" {code}: {lang.name}")191 for script in lang.scripts:192 print(f" {script.code} -> {[t.code for t in script.to_scripts]}")193194# Dictionary languages195print("\nDictionary languages:")196for code, lang in languages.dictionary.items():197 print(f" {code}: {lang.name}")198```199200## Break Sentence201202Identify sentence boundaries:203204```python205result = client.find_sentence_boundaries(206 body=["Hello! How are you? I hope you are well."],207 language="en"208)209210for item in result:211 print(f"Sentence lengths: {item.sent_len}")212```213214## Translation Options215216```python217result = client.translate(218 body=["Hello, world!"],219 to=["de"],220 text_type="html", # "plain" or "html"221 profanity_action="Marked", # "NoAction", "Deleted", "Marked"222 profanity_marker="Asterisk", # "Asterisk", "Tag"223 include_alignment=True, # Include word alignment224 include_sentence_length=True # Include sentence boundaries225)226227for item in result:228 translation = item.translations[0]229 print(f"Translated: {translation.text}")230 if translation.alignment:231 print(f"Alignment: {translation.alignment.proj}")232 if translation.sent_len:233 print(f"Sentence lengths: {translation.sent_len.src_sent_len}")234```235236## Async Client237238```python239from azure.ai.translation.text.aio import TextTranslationClient240from azure.core.credentials import AzureKeyCredential241242async def translate_text():243 async with TextTranslationClient(244 credential=AzureKeyCredential(key),245 region=region246 ) as client:247 result = await client.translate(248 body=["Hello, world!"],249 to=["es"]250 )251 print(result[0].translations[0].text)252```253254## Client Methods255256| Method | Description |257|--------|-------------|258| `translate` | Translate text to one or more languages |259| `transliterate` | Convert text between scripts |260| `detect` | Detect language of text |261| `find_sentence_boundaries` | Identify sentence boundaries |262| `lookup_dictionary_entries` | Dictionary lookup for translations |263| `lookup_dictionary_examples` | Get usage examples |264| `get_supported_languages` | List supported languages |265266## Best Practices2672681. **Batch translations** — Send multiple texts in one request (up to 100)2692. **Specify source language** when known to improve accuracy2703. **Use async client** for high-throughput scenarios2714. **Cache language list** — Supported languages don't change frequently2725. **Handle profanity** appropriately for your application2736. **Use html text_type** when translating HTML content2747. **Include alignment** for applications needing word mapping275
Full transparency — inspect the skill content before installing.