tessl install tessl/pypi-googletrans@4.0.0An 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%
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.
The service should provide a function that:
Accepts text content as a string
Accepts a declared language in any of these formats:
Validates that the provided language identifier is supported
Detects the actual language of the provided text
Returns a validation result indicating whether the text matches the declared language, including:
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
@generates
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
"""
passProvides translation and language detection services with flexible language code handling.