Language Detector In Python

Hello friends, in this segment we are going to discuss how to make a language detector program using Python. So let me tell you how the language detector works. It simply takes input from the user in the form of text and provides the result to the user that, in which language this text is written.

Before start writing the code, we will have to install two modules and the name of the modules are textblob and pycountry. For installing these modules we will have to go to Windows PowerShell and write pip install textblob for installing the textblob and pip install pycountry for installing the pycountry.

Python Language Detector

As in the above paragraph, I told you that before writing the code for language detection we will have to install the textblob and the pycountry after installing these modules. We are ready to write the Python program for language detection.

here is the code:

from  textblob import TextBlob as TB
import pycountry
word = input('Type something in your preferred language:')
text = TB(word)
iso_code = text.detect_language()
language = pycountry.languages.get(alpha_2=iso_code)
language_name =
print(f'Language Detected:{language_name}')


Type something in your preferred language:je suis un developpeur python
Language Detected:French

Also read: Gamma Function In Python

As we can see the output, here is the text which is inputted by the user. Our program is telling that in which language this text is written. Let us talk about the code, from textblob we have to import Textblob as TB and we also have to import pycountry. Now we will take a variable for storing the inputted text, as we can see I have taken a variable word for storing the inputted text. After storing the text into the variable we have to pass the variable as an argument in TB. This text goes to textblob, textblob is a python library it provides a simple API for natural language processing(NLP). In the above code, I used pycountry it is also a python library it is used to access ISO country.

One response to “Language Detector In Python”

  1. Arun M v says:

    Not able to use the text blob as the google api blocks the request. Please suggest alternate or work around as I am not able to get other libraries which give accurate answers like this.

Leave a Reply

Your email address will not be published. Required fields are marked *