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

text-translation.mddocs/

Text Translation

Neural machine translation service that renders source text into multiple target languages simultaneously. Supports advanced features including automatic language detection, profanity filtering, text alignment analysis, custom translation models, and sentence boundary detection.

Capabilities

Translate Text

Translates input text from source language to one or more target languages using neural machine translation with extensive customization options.

def translate(
    body: Union[List[str], List[InputTextItem], IO[bytes]],
    *,
    to_language: List[str],
    client_trace_id: Optional[str] = None,
    from_language: Optional[str] = None,
    text_type: Optional[Union[str, TextType]] = None,
    category: Optional[str] = None,
    profanity_action: Optional[Union[str, ProfanityAction]] = None,
    profanity_marker: Optional[Union[str, ProfanityMarker]] = None,
    include_alignment: Optional[bool] = None,
    include_sentence_length: Optional[bool] = None,
    suggested_from: Optional[str] = None,
    from_script: Optional[str] = None,
    to_script: Optional[str] = None,
    allow_fallback: Optional[bool] = None,
    **kwargs: Any
) -> List[TranslatedTextItem]

Parameters:

  • body: Text to translate (strings, InputTextItem objects, or binary data)
  • to_language: Target language codes (e.g., ["es", "fr", "de"])
  • from_language: Source language code (auto-detected if omitted)
  • text_type: Content type (Plain or Html)
  • category: Custom translator model category ID
  • profanity_action: Profanity handling (NoAction, Marked, Deleted)
  • profanity_marker: Profanity marking style (Asterisk, Tag)
  • include_alignment: Include word alignment projection
  • include_sentence_length: Include sentence boundary information
  • suggested_from: Fallback language for failed detection
  • from_script/to_script: Script specifications for transliteration
  • allow_fallback: Allow fallback to general models for custom categories

Returns: List of translation results with metadata

Usage Examples

from azure.ai.translation.text import TextTranslationClient
from azure.ai.translation.text.models import TextType, ProfanityAction
from azure.core.credentials import AzureKeyCredential

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

# Basic translation to multiple languages
response = client.translate(
    body=["Hello, how are you?"],
    to_language=["es", "fr", "de"]
)

for translation in response:
    print(f"Detected language: {translation.detected_language.language}")
    for result in translation.translations:
        print(f"{result.to}: {result.text}")

# HTML content translation with profanity filtering
html_response = client.translate(
    body=["<p>This is a <b>damn</b> good example!</p>"],
    to_language=["es"],
    text_type=TextType.HTML,
    profanity_action=ProfanityAction.MARKED,
    profanity_marker="Asterisk"
)

# Translation with alignment and sentence information
detailed_response = client.translate(
    body=["Hello world. How are you today?"],
    to_language=["es"],
    include_alignment=True,
    include_sentence_length=True
)

translation = detailed_response[0].translations[0]
print(f"Alignment: {translation.alignment.proj}")
print(f"Source sentences: {translation.sent_len.src_sent_len}")
print(f"Target sentences: {translation.sent_len.trans_sent_len}")

# Custom model translation
custom_response = client.translate(
    body=["Technical documentation text"],
    to_language=["ja"],
    from_language="en",
    category="your-custom-model-id",
    allow_fallback=False
)

Input Types

Text Input Models

class InputTextItem:
    text: str  # Text content to translate

Text Content Types

class TextType(str, Enum):
    PLAIN = "Plain"  # Plain text content (default)
    HTML = "Html"    # HTML markup content

Profanity Handling

class ProfanityAction(str, Enum):
    NO_ACTION = "NoAction"  # Leave profanity unchanged (default)
    MARKED = "Marked"       # Mark profanity with specified marker
    DELETED = "Deleted"     # Remove profanity entirely

class ProfanityMarker(str, Enum):
    ASTERISK = "Asterisk"  # Replace with asterisks (default)
    TAG = "Tag"            # Wrap with XML tags

Response Types

Translation Results

class TranslatedTextItem:
    translations: List[TranslationText]  # Translation results per target language
    detected_language: Optional[DetectedLanguage]  # Auto-detected source language
    source_text: Optional[SourceText]  # Original text in default script

Individual Translation

class TranslationText:
    text: str  # Translated text
    to: str    # Target language code
    alignment: Optional[TranslatedTextAlignment]  # Word alignment data
    sent_len: Optional[SentenceBoundaries]  # Sentence length information
    transliteration: Optional[dict]  # Script conversion result

Language Detection

class DetectedLanguage:
    language: str  # Detected language code
    score: float   # Confidence score (0.0 to 1.0)

Text Alignment Analysis

class TranslatedTextAlignment:
    proj: str  # Alignment projection string
    # Format: [[SourceStart:SourceEnd–TargetStart:TargetEnd] ...]

Sentence Boundary Information

class SentenceBoundaries:
    src_sent_len: List[int]    # Source sentence lengths
    trans_sent_len: List[int]  # Translated sentence lengths

Source Text Information

class SourceText:
    text: str  # Input text in default script of source language

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