|
|
|
|
|
""" |
|
|
Debug script to test translation functionality |
|
|
""" |
|
|
|
|
|
import os |
|
|
import asyncio |
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
from translator import DocumentTranslator |
|
|
|
|
|
async def test_translation(): |
|
|
"""Test the translation system""" |
|
|
print("π§ͺ Testing Document Translation System...") |
|
|
|
|
|
|
|
|
api_key = os.getenv('OPENROUTER_API_KEY') |
|
|
if not api_key: |
|
|
print("β OPENROUTER_API_KEY not found!") |
|
|
print("Set it with: export OPENROUTER_API_KEY='your_key_here'") |
|
|
return |
|
|
|
|
|
print(f"β
API key found (length: {len(api_key)})") |
|
|
|
|
|
|
|
|
translator = DocumentTranslator() |
|
|
|
|
|
if not translator.is_ready(): |
|
|
print("β Translator not ready") |
|
|
return |
|
|
|
|
|
print("β
Translator initialized") |
|
|
|
|
|
|
|
|
models = await translator.get_available_models() |
|
|
print(f"β
Available models: {len(models)}") |
|
|
for model in models: |
|
|
print(f" - {model['name']}: {model['id']}") |
|
|
|
|
|
|
|
|
test_text = "Hello, this is a test sentence for translation." |
|
|
print(f"\nπ€ Testing basic translation...") |
|
|
print(f"Original: {test_text}") |
|
|
|
|
|
try: |
|
|
translated = await translator.translate_text( |
|
|
test_text, |
|
|
"google/gemini-2.5-pro-exp-03-25", |
|
|
"en", |
|
|
"ar" |
|
|
) |
|
|
print(f"Translated: {translated}") |
|
|
|
|
|
if translated != test_text: |
|
|
print("β
Basic translation working!") |
|
|
else: |
|
|
print("β οΈ Translation returned original text - check API key and credits") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β Translation test failed: {e}") |
|
|
|
|
|
print("\nπ― Translation system test complete!") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
asyncio.run(test_translation()) |