CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-googletrans

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

Overall
score

100%

Evaluation100%

1.01x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-6/

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.

Install with Tessl CLI

npx tessl i tessl/pypi-googletrans@4.0.0

tile.json