CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-ai-translation-text

Azure Text Translation client library for Python that provides neural machine translation technology for quick and accurate source-to-target text translation in real time across all supported languages

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

script-transliteration.mddocs/

Script Transliteration

Convert text from one script to another within the same language, preserving pronunciation and meaning. Supports conversions like Latin to Cyrillic, Arabic to Latin, Devanagari to Latin, and many other script pairs for supported languages.

Capabilities

Transliterate Text

Converts characters or letters of input text from one script to corresponding characters in a target script while maintaining linguistic meaning.

def transliterate(
    body: Union[List[str], List[InputTextItem], IO[bytes]],
    *,
    language: str,
    from_script: str,
    to_script: str,
    client_trace_id: Optional[str] = None,
    **kwargs: Any
) -> List[TransliteratedText]

Parameters:

  • body: Text to transliterate (strings, InputTextItem objects, or binary data)
  • language: Language code for the text (e.g., "zh-Hans", "ar", "hi")
  • from_script: Source script identifier (e.g., "Hans", "Arab", "Deva")
  • to_script: Target script identifier (e.g., "Latn", "Cyrl")
  • client_trace_id: Client-generated GUID for request tracking

Returns: List of transliteration results with script information

Usage Examples

from azure.ai.translation.text import TextTranslationClient
from azure.core.credentials import AzureKeyCredential

client = TextTranslationClient(
    credential=AzureKeyCredential("your-api-key"),
    region="your-region"
)

# Chinese to Latin transliteration
chinese_response = client.transliterate(
    body=["这是个测试。"],
    language="zh-Hans",
    from_script="Hans",
    to_script="Latn"
)

for result in chinese_response:
    print(f"Original script: {result.script}")
    print(f"Transliterated: {result.text}")
    # Output: "zhè shì gè cè shì。"

# Arabic to Latin transliteration
arabic_response = client.transliterate(
    body=["مرحبا بالعالم"],
    language="ar",
    from_script="Arab",
    to_script="Latn"
)

# Hindi to Latin transliteration
hindi_response = client.transliterate(
    body=["नमस्ते दुनिया"],
    language="hi", 
    from_script="Deva",
    to_script="Latn"
)

# Russian Cyrillic to Latin transliteration
russian_response = client.transliterate(
    body=["Привет мир"],
    language="ru",
    from_script="Cyrl", 
    to_script="Latn"
)

# Multiple texts in single request
multiple_response = client.transliterate(
    body=["第一个测试", "第二个例子"],
    language="zh-Hans",
    from_script="Hans",
    to_script="Latn"
)

for i, result in enumerate(multiple_response):
    print(f"Text {i+1}: {result.text}")

Input Types

Text Input Models

class InputTextItem:
    text: str  # Text content to transliterate

Response Types

Transliteration Results

class TransliteratedText:
    script: str  # Target script identifier used in output
    text: str    # Transliterated text in target script

Script Discovery

Use the language support endpoint to discover available script conversions:

# Get transliteration languages and their supported scripts
response = client.get_supported_languages(scope="transliteration")

if response.transliteration:
    for lang_code, lang_info in response.transliteration.items():
        print(f"\nLanguage: {lang_code} ({lang_info.name})")
        
        for script in lang_info.scripts:
            print(f"  From script: {script.code} ({script.name})")
            print(f"  Available conversions:")
            
            for target_script in script.to_scripts:
                print(f"    -> {target_script.code} ({target_script.name})")

Common Script Codes

Source Scripts

  • Hans: Simplified Chinese characters
  • Hant: Traditional Chinese characters
  • Arab: Arabic script
  • Deva: Devanagari (Hindi, Sanskrit)
  • Cyrl: Cyrillic (Russian, Bulgarian, etc.)
  • Gujr: Gujarati script
  • Guru: Gurmukhi (Punjabi)
  • Hebr: Hebrew script
  • Jpan: Japanese (Hiragana/Katakana/Kanji)
  • Kore: Korean (Hangul/Hanja)
  • Thai: Thai script

Target Scripts

  • Latn: Latin alphabet
  • Cyrl: Cyrillic script
  • Arab: Arabic script
  • Hans: Simplified Chinese
  • Hant: Traditional Chinese

Error Handling

from azure.core.exceptions import HttpResponseError

try:
    response = client.transliterate(
        body=["Invalid text for script"],
        language="zh-Hans",
        from_script="InvalidScript",  # Invalid script code
        to_script="Latn"
    )
except HttpResponseError as error:
    if error.error:
        print(f"Error Code: {error.error.code}")
        print(f"Message: {error.error.message}")

Install with Tessl CLI

npx tessl i tessl/pypi-azure-ai-translation-text

docs

dictionary-operations.md

index.md

language-support.md

script-transliteration.md

sentence-boundaries.md

text-translation.md

tile.json