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

Multi-Environment Translation Service

Build a translation service that works across different deployment environments with configurable translator settings.

Overview

Your task is to create a translation service module that initializes translators with different configurations based on environment requirements. The service should support multiple deployment scenarios (production, testing, and restricted networks) with appropriate translator settings.

Requirements

Create a Python module that provides translator instances configured for three different environments:

Production Translator

  • Uses the stable Google API endpoint for reliability
  • Enables HTTP/2 for better performance
  • Uses default error handling (returns None on failures rather than raising exceptions)

Development Translator

  • Uses the standard Google Translate web endpoint
  • Raises exceptions on errors for easier debugging
  • Uses a custom user agent string: "DevBot/1.0"

Restricted Network Translator

  • Uses an alternative regional endpoint: "translate.google.co.kr"
  • Disables HTTP/2 for compatibility with older network infrastructure
  • Raises exceptions on errors

Service Interface

Implement a function get_translator(environment: str) that returns an appropriately configured translator instance based on the environment parameter. The function should accept "production", "development", or "restricted" as valid environment values.

Test Cases

  • When requesting a "production" translator, it returns a translator configured with the googleapis endpoint and HTTP/2 enabled @test
  • When requesting a "development" translator, it returns a translator with raise_exception enabled and custom user agent @test
  • When requesting a "restricted" translator, it returns a translator using the Korean endpoint with HTTP/2 disabled @test
  • When requesting an invalid environment name, it raises a ValueError @test

@generates

API

def get_translator(environment: str):
    """
    Returns a configured translator instance for the specified environment.

    Args:
        environment: One of "production", "development", or "restricted"

    Returns:
        A configured Translator instance

    Raises:
        ValueError: If environment is not recognized
    """
    pass

Dependencies { .dependencies }

googletrans { .dependency }

Provides translation services via Google Translate API.