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

Multi-Language Text Validator

Build a text validation service that verifies whether text content matches its declared language. The service should accept text content along with language identifiers in various formats and determine if the text is actually written in the declared language.

Requirements

The service should provide a function that:

  1. Accepts text content as a string

  2. Accepts a declared language in any of these formats:

    • Language codes (e.g., "en", "ko", "ja")
    • Full language names (e.g., "english", "korean", "japanese")
    • Case-insensitive formats (e.g., "ENGLISH", "English")
    • RFC 1766 format (e.g., "en_US", "zh_CN")
  3. Validates that the provided language identifier is supported

  4. Detects the actual language of the provided text

  5. Returns a validation result indicating whether the text matches the declared language, including:

    • Whether validation passed or failed
    • The normalized language code that was declared
    • The detected language code
    • The confidence score of the detection

Test Cases

  • Given text "Hello, how are you?" with declared language "english", it returns a passing validation with normalized code "en" and detected language "en" @test

  • Given text "Bonjour, comment allez-vous?" with declared language "FR", it returns a passing validation with normalized code "fr" and detected language "fr" @test

  • Given text "こんにちは、元気ですか?" with declared language "ja_JP", it returns a passing validation with normalized code "ja" and detected language "ja" @test

  • Given text "Hello world" with declared language "spanish", it returns a failing validation showing mismatch between declared "es" and detected "en" @test

  • Given text with declared language "invalid_lang", it raises an error for unsupported language @test

Implementation

@generates

API

from typing import Dict, Any

async def validate_text_language(text: str, declared_language: str) -> Dict[str, Any]:
    """
    Validates whether text content matches its declared language.

    Args:
        text: The text content to validate
        declared_language: The declared language in any supported format

    Returns:
        A dictionary containing:
        - is_valid: bool indicating if text matches declared language
        - declared_code: normalized language code of declared language
        - detected_code: detected language code from the text
        - confidence: float confidence score of the detection

    Raises:
        ValueError: If the declared language is not supported
    """
    pass

Dependencies { .dependencies }

googletrans { .dependency }

Provides translation and language detection services with flexible language code handling.