All skills
microsoft avatar

/azure-ai-translation-text-py

@e19efc2
by microsoftmicrosoft/skills3.1k stars
351

Azure AI Text Translation SDK for real-time text translation, transliteration, language detection, and dictionary lookup. Use for translating text content in applications. Triggers: "text translation", "translator", "translate text", "transliterate", "TextTranslationClient".

Use this Skill: https://skilld.dev/gh/microsoft/skills/azure-ai-translation-text-py

This session only. Nothing lands on disk.

referencesnon-hero-scenarios.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

azure-ai-translation-text-py non-hero scenarios

These scenarios are intentionally separate from hero flows in SKILL.md. They cover secondary/advanced patterns typically used after the primary end-to-end path is working.

Transliteration

Convert text from one script to another:

from azure.ai.translation.text.models import InputTextItem

result = client.transliterate(
    body=[InputTextItem(text="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:

from azure.ai.translation.text.models import InputTextItem

result = client.lookup_dictionary_entries(
    body=[InputTextItem(text="fly")],
    from_language="en",
    to_language="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_language="en",
    to_language="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:

from azure.ai.translation.text.models import InputTextItem

result = client.find_sentence_boundaries(
    body=[InputTextItem(text="Hello! How are you? I hope you are well.")],
    language="en"
)

for item in result:
    print(f"Sentence lengths: {item.sent_len}")

Translation Options

from azure.ai.translation.text.models import InputTextItem

result = client.translate(
    body=[InputTextItem(text="Hello, world!")],
    to_language=["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.ai.translation.text.models import InputTextItem
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=[InputTextItem(text="Hello, world!")],
                to_language=["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

Source: SKILL.md on GitHub

1 warning15d4 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    This skill provides integration with Azure AI Text Translation services and follows security best practices such as using Entra ID authentication and managed identities. It includes a potential consideration regarding indirect prompt injection since its primary function is to process and translate external text content.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

  • Runlayer7mo

    2/2 files flagged

Signed by skilld at e19efc2. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 19 hours ago.

Activeupdated 3 months ago
Other metadata
metadata
{
  "author": "Microsoft",
  "version": "1.0.0",
  "package": "azure-ai-translation-text"
}

README badge

README badge for microsoft/skills/azure-ai-translation-text-py