Detect an Unknown Language using Python
Last Updated :
28 Apr, 2025
The idea behind language detection is based on the detection of the character among the expression and words in the text. The main principle is to detect commonly used words like to, of in English. Python provides various modules for language detection. In this article, the modules covered are:
Method 1: Using langdetect library This module is a port of Google's language-detection library that supports 55 languages. This module don't come with Python's standard utility modules. So, it is needed to be installed externally. To install this type the below command in the terminal.
pip install langdetect
Python3
# Python program to demonstrate
# langdetect
from langdetect import detect
# Specifying the language for
# detection
print(detect("Geeksforgeeks is a computer science portal for geeks"))
print(detect("Geeksforgeeks - это компьютерный портал для гиков"))
print(detect("Geeksforgeeks es un portal informático para geeks"))
print(detect("Geeksforgeeks是面向极客的计算机科学门户"))
print(detect("Geeksforgeeks geeks के लिए एक कंप्यूटर विज्ञान पोर्टल है"))
print(detect("Geeksforgeeksは、ギーク向けのコンピューターサイエンスポータルです。"))
Output:
en
ru
es
no
hi
ja
Method 2: Using textblob library This module is used for natural language processing(NLP) tasks such as noun phrase extraction, sentiment analysis, classification, translation, and more. To install this module type the below command in the terminal. ('ru', -641.3409600257874)
pip install textblob
Example:
Python3
# Python program to demonstrate
# textblob
from textblob import TextBlob
L = ["Geeksforgeeks is a computer science portal for geeks",
"Geeksforgeeks - это компьютерный портал для гиков",
"Geeksforgeeks es un portal informático para geeks",
"Geeksforgeeks是面向极客的计算机科学门户",
"Geeksforgeeks geeks के लिए एक कंप्यूटर विज्ञान पोर्टल है",
"Geeksforgeeksは、ギーク向けのコンピューターサイエンスポータルです。",
]
for i in L:
# Language Detection
lang = TextBlob(i)
print(lang.detect_language())
Output:
en
ru
es
zh-CN
hi
ja
Method 3: Using langid library This module is a standalone Language Identification tool. It is pre-trained over a large number of languages (currently 97). It is a single.py file with minimal dependencies. To install this type the below command in the terminal.
pip install langid
[src: https://github.com/saffsd/langid.py]
Example:
Python3
# Python program to demonstrate
# langid
import langid
L = ["Geeksforgeeks is a computer science portal for geeks",
"Geeksforgeeks - это компьютерный портал для гиков",
"Geeksforgeeks es un portal informático para geeks",
"Geeksforgeeks是面向极客的计算机科学门户",
"Geeksforgeeks geeks के लिए एक कंप्यूटर विज्ञान पोर्टल है",
"Geeksforgeeksは、ギーク向けのコンピューターサイエンスポータルです。",
]
for i in L:
# Language detection
print(langid.classify(i))
Output:
('en', -119.93012762069702)
('ru', -641.3409600257874)
('es', -191.01083326339722)
('zh', -199.18277835845947)
('hi', -286.99300467967987)
('ja', -875.6610476970673)
Similar Reads
Language Detection in Python using Tkinter Prerequisite: Tkinter In this article, we will learn about language detection Using Python in Tkinter. In Simple Words, language identification is the problem of determining which natural language given content is in. Modules UsedTkinter module is used in Python to create GUI based interfaces.For La
2 min read
Language Translator Using Google API in Python API stands for Application Programming Interface. It acts as an intermediate between two applications or software. In simple terms, API acts as a messenger that takes your request to destinations and then brings back its response for you. Google API is developed by Google to allow communications wit
3 min read
How to Create a Programming Language using Python? In this article, we are going to learn how to create your own programming language using SLY(Sly Lex Yacc) and Python. Before we dig deeper into this topic, it is to be noted that this is not a beginner's tutorial and you need to have some knowledge of the prerequisites given below. PrerequisitesRou
7 min read
Multilingual Dictionary App Using Python In this article, we will guide you through the process of creating a Multilingual Dictionary app using Python. The core functionality of this application involves translating words using the OpenAI API. To provide a user-friendly interface, we will leverage the Streamlit library. With this setup, tr
5 min read
Language Learning App using Django In this article, we will guide you through creating a language-learning application using Django in Python. Language Learning App Using DjangoBelow, is the step-by-step Implementation of a language learning app using Django in Python: Starting the Project FolderTo start the project use this command
15 min read
Unknown facts about Python Python is a widely-used general-purpose, high-level programming language. It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more eff
4 min read