Krishna086's picture
Update lang_detect.py
42904fe verified
raw
history blame
633 Bytes
from langdetect import detect
def detect_language(text):
"""Detect the language of input text."""
try:
lang_code = detect(text)
# Map langdetect codes to our LANGUAGES
lang_map = {
"English": "en",
"French": "fr",
"Spanish": "es",
"German": "de",
"Chinese": "zh",
"Arabic": "ar",
"Russian": "ru",
"Hindi": "hi",
"Japanese": "ja"
}
return lang_map.get(lang_code, "English") # Default to English if not mapped
except:
return "English" # Fallback if detection fails