Langdetect for n8n

This commit is contained in:
Jonas Linter
2025-10-15 14:12:57 +02:00
parent 361611ae1b
commit d9e45fed36
3 changed files with 139 additions and 0 deletions

52
test_langdetect.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""
Test script for fast-langdetect library
Tests language detection on various sample texts
"""
from fast_langdetect import detect
# Test strings in different languages
test_strings = [
("Hello, how are you doing today?", "English"),
("Bonjour, comment allez-vous aujourd'hui?", "French"),
("Hola, ¿cómo estás hoy?", "Spanish"),
(
"Hallo, ich würde diese Wohnung gerne am 22.10.25 am späten Nachmittag besichtigen. Wir reisen aus Berlin an. Mit freundlichen Grüßen Dr. Christoph Garcia Bartels",
"German",
),
("Ciao, come stai oggi?", "Italian"),
("Olá, como você está hoje?", "Portuguese"),
("Привет, как дела сегодня?", "Russian"),
("こんにちは、今日はお元気ですか?", "Japanese"),
("你好,你今天怎么样?", "Chinese"),
(
"Ciao, questo appartamento mi interessa e mi piacerebbe visitarlo. Grazie",
"Italian",
),
("مرحبا، كيف حالك اليوم؟", "Arabic"),
("Hej, hur mår du idag?", "Swedish"),
(
"Guten Tag! Koennte ich diese Wohnun bitte besichtigen kommen? Vielleicht sogar schon morgen, Mittwoch den 15.10.? Ich waere sowieso im Unterland und koennte gegen 12 Uhr dort sein. Danke fuer eine kurze Rueckmeldung diesbezueglich, Catherina",
"German",
),
("Witam, jak się dzisiaj masz?", "Polish"),
]
def main():
print("Testing fast-langdetect library")
print("=" * 60)
print()
for text, expected_lang in test_strings:
detected = detect(text)
print(f"Text: {text[:50]}...")
print(f"Expected: {expected_lang}")
print(f"Detected: {detected}")
print("-" * 60)
print()
if __name__ == "__main__":
main()