Discover the language.
Lets try and unbox Python langdetect library, which will be very useful for text processing and linguistic tasks. This is a language detection library implemented in plain Java.
Python Knowledge Base: Make coding great again.
- Updated:
2024-11-10 by Andrey BRATUS, Senior Data Analyst.
Lets install langdetect.
Lets detect english text.
Lets detect spanish text.
Lets detect russian text.
Lets detect french text.
Lets detect chinese text.
As stated in pypi.org langdetect supports 55 languages out of the box , now maybe even more. So let's try some practical examples !
pip install langdetect
from langdetect import detect
try_text="My daughter just revealed to me she's transexual... I guess that makes me transparent."
detect(try_text)
OUT: en
try_text2='Hoy pasaré por la biblioteca para devolver los libros.'
detect(try_text2)
OUT: es
try_text3="Ночь темна и полна ужасов, а холодильник светел и полон обещаний."
detect(try_text3)
OUT: ru
try_text4="La pire position sexuelle c'est quand t'es allongé en dessous et qu'au dessus il n'y a personne..."
detect(try_text4)
OUT: fr
try_text5='''妈妈说:“今天能完成的事,不要留到明天。”
儿子回答:“好吧,把全蛋糕给我,我今天都吃光了吧。'''
detect(try_text5)
OUT: zh-cn