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

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.

Install with Tessl CLI

npx tessl i tessl/pypi-googletrans@4.0.0

tile.json