An unofficial Google Translate API for Python providing free text translation and language detection capabilities
Overall
score
100%
Evaluation — 100%
↑ 1.01xAgent success when using this tile
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.
Install with Tessl CLI
npx tessl i tessl/pypi-googletrans@4.0.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10