or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/googletrans@4.0.x
tile.json

tessl/pypi-googletrans

tessl install tessl/pypi-googletrans@4.0.0

An unofficial Google Translate API for Python providing free text translation and language detection capabilities

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.01x

Baseline

Agent success rate without this tile

99%

task.mdevals/scenario-2/

Robust Translation Service

Build a translation service that gracefully handles errors when the translation API is unavailable or encounters issues.

Overview

Create a service that wraps translation functionality and handles failures gracefully. The service should support two error handling modes: silent mode (returns fallback data) and explicit mode (raises exceptions).

Capabilities

Silent Error Mode

Return fallback data when errors occur instead of crashing.

  • Translate "hello" to French using silent error mode, successfully returning translated text @test
  • When translation fails in silent mode, return the original text as fallback @test

Explicit Error Mode

Allow errors to propagate for explicit handling.

  • Translate "hello" to French using explicit error mode, successfully returning translated text @test
  • When translation fails in explicit mode, raise an exception that can be caught and handled @test

Language Detection with Error Handling

Detect languages with proper error handling in both modes.

  • Detect the language of "Bonjour le monde" in silent mode and return language code with confidence @test
  • When detection fails in explicit mode, raise an exception @test

Implementation

@generates

API

class TranslatorService:
    """A translation service wrapper with configurable error handling."""

    def __init__(self, silent_errors: bool = False) -> None:
        """
        Initialize the translator service.

        Args:
            silent_errors: If True, return fallback data on errors.
                         If False, raise exceptions on errors.
        """
        pass

    async def translate(self, text: str, dest_lang: str) -> dict:
        """
        Translate text to the destination language.

        Args:
            text: The text to translate
            dest_lang: Destination language code (e.g., 'fr', 'es', 'ja')

        Returns:
            dict with keys:
                - 'translated_text': str with translated text (or original if failed in silent mode)
                - 'source_lang': str with detected source language
                - 'dest_lang': str with destination language
                - 'success': bool indicating if translation succeeded
        """
        pass

    async def detect_language(self, text: str) -> dict:
        """
        Detect the language of the input text.

        Args:
            text: The text to analyze

        Returns:
            dict with keys:
                - 'language': str language code
                - 'confidence': float between 0.0 and 1.0
        """
        pass

    async def close(self) -> None:
        """Close the translator and clean up resources."""
        pass

Dependencies { .dependencies }

googletrans { .dependency }

Provides translation and language detection capabilities with configurable error handling.

@satisfied-by