File size: 410 Bytes
b5f1359 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from langdetect import detect
import pycountry
import langid
class Lang:
def __init__(self, text, options=None):
if options:
langid.set_languages(options) # ISO 639-1 codes
self.lang_code, _ = langid.classify(text)
else:
self.lang_code = detect(text[:1000])
self.lang_name = pycountry.languages.get(alpha_2=self.lang_code).name |