Unlock the Power of Language Detection with Python.

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.

Language detection with Python.
Language detection meme.

Python Knowledge Base: Make coding great again.
- Updated: 2024-11-20 by Andrey BRATUS, Senior Data Analyst.



    As stated in pypi.org langdetect supports 55 languages out of the box , now maybe even more. So let's try some practical examples !



  1. Lets install langdetect.


  2.         
    pip install langdetect
    
    from langdetect import detect
    

  3. Lets detect english text.


  4.         
    try_text="My daughter just revealed to me she's transexual... I guess that makes me transparent."
    detect(try_text)
    

    OUT: en


  5. Lets detect spanish text.


  6.         
    try_text2='Hoy pasaré por la biblioteca para devolver los libros.'
    detect(try_text2)
    

    OUT: es



  7. Lets detect russian text.


  8.         
    try_text3="Ночь темна и полна ужасов, а холодильник светел и полон обещаний."
    detect(try_text3)
    

    OUT: ru


  9. Lets detect french text.


  10.         
    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



  11. Lets detect chinese text.


  12.         
    try_text5='''妈妈说:“今天能完成的事,不要留到明天。”
    
    儿子回答:“好吧,把全蛋糕给我,我今天都吃光了吧。'''
    detect(try_text5)
    

    OUT: zh-cn





See also related topics: