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-7/

Multi-Language Content Processor

Build a content processor that handles translation and language detection with proper type annotations.

Requirements

Implement a ContentProcessor class that:

  1. Translates single texts or lists of texts
  2. Detects languages for single texts or lists of texts
  3. Returns correctly typed results based on input type (single result for string, list for list input)
  4. Uses proper async operations
  5. Manages translator lifecycle properly

API

import typing
from googletrans import Translator, Translated, Detected

class ContentProcessor:
    """Processes content with translation and detection capabilities."""

    def __init__(self, target_lang: str = "en") -> None:
        """
        Initialize the content processor.

        Args:
            target_lang: Default target language for translations
        """
        pass

    async def translate_content(
        self,
        content: typing.Union[str, typing.List[str]],
        dest: str = None
    ) -> typing.Union[Translated, typing.List[Translated]]:
        """
        Translate content to target language.

        Args:
            content: Text or list of texts to translate
            dest: Destination language (uses default if None)

        Returns:
            Single Translated object for string input,
            List of Translated objects for list input
        """
        pass

    async def detect_languages(
        self,
        content: typing.Union[str, typing.List[str]]
    ) -> typing.Union[Detected, typing.List[Detected]]:
        """
        Detect language(s) of content.

        Args:
            content: Text or list of texts to detect

        Returns:
            Single Detected object for string input,
            List of Detected objects for list input
        """
        pass

    async def close(self) -> None:
        """Clean up resources."""
        pass

Test Cases

  • Translating a single string "Hello world" to Spanish returns a Translated object with text "Hola mundo" @test
  • Translating a list ["Hello", "Goodbye"] to French returns a list of two Translated objects @test
  • Detecting language of "Bonjour" returns a Detected object with lang="fr" @test
  • Detecting languages of ["Hello", "Hola", "Bonjour"] returns a list of three Detected objects @test
  • The processor properly manages translator resources through the close method @test

Implementation

@generates

Dependencies { .dependencies }

googletrans { .dependency }

Provides translation and language detection with type-safe APIs.