-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (22 loc) · 709 Bytes
/
main.py
File metadata and controls
25 lines (22 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Language Detector
from langdetect import detect, DetectorFactory
DetectorFactory.seed = 0 # Ensure consistent results
def detect_language(text):
"""Detect the language of a given text and return code + name."""
lang_code = detect(text)
language_mapping = {
'es': 'Spanish',
'en': 'English',
'sw': 'Swahili',
'guz': 'Kisii' # ISO 639-3 code for Ekegusii (Kisii)
}
return lang_code, language_mapping.get(lang_code, lang_code)
# Sample texts
texts = [
'¿Qué te gusta hacer',
'Nyasae no omuya'
]
# Detect and print results
for text in texts:
code, name = detect_language(text)
print(f'This is the {name} language shortened by: {code}')