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 translation service that gracefully handles errors when the translation API is unavailable or encounters issues.
Create a service that wraps translation functionality and handles failures gracefully. The service should support two error handling modes: silent mode (returns fallback data) and explicit mode (raises exceptions).
Return fallback data when errors occur instead of crashing.
Allow errors to propagate for explicit handling.
Detect languages with proper error handling in both modes.
@generates
class TranslatorService:
"""A translation service wrapper with configurable error handling."""
def __init__(self, silent_errors: bool = False) -> None:
"""
Initialize the translator service.
Args:
silent_errors: If True, return fallback data on errors.
If False, raise exceptions on errors.
"""
pass
async def translate(self, text: str, dest_lang: str) -> dict:
"""
Translate text to the destination language.
Args:
text: The text to translate
dest_lang: Destination language code (e.g., 'fr', 'es', 'ja')
Returns:
dict with keys:
- 'translated_text': str with translated text (or original if failed in silent mode)
- 'source_lang': str with detected source language
- 'dest_lang': str with destination language
- 'success': bool indicating if translation succeeded
"""
pass
async def detect_language(self, text: str) -> dict:
"""
Detect the language of the input text.
Args:
text: The text to analyze
Returns:
dict with keys:
- 'language': str language code
- 'confidence': float between 0.0 and 1.0
"""
pass
async def close(self) -> None:
"""Close the translator and clean up resources."""
passProvides translation and language detection capabilities with configurable error handling.
@satisfied-by