Language Detection of a Sentence using Python With Source Code

Introduction
Hello Curious Coders,
In this project, we are going to learn how to detect the language in text using Python with the help of libraries like long detect. This parses through the basic functions of langdetect library and is going to detect the sentence of a language.
Source Code
Get Discount on Top Educational Courses
# Importing langdetect library
from langdetect import detect
# Function to detect the language of a sentence
def detect_language(text):
return detect(text)
# The Sentence
text = "வணக்கம்"
# Dictionary of some famous Languages and their respective codes
codes={
'ar': 'Arabic', 'et': 'Armenian', 'art': 'Artificial Langauge',
'sq': 'Albanian','bn': 'Bangla', 'bh': 'Bhojpuri',
'bul': 'Bulgarian', 'cai': 'Central American Indian Language',
'cze': 'Caech', 'dan': 'Danish', 'ger': 'German', 'eg': 'Egyptian', 'en': 'English',
'fre': 'french', 'gon': 'Gondi', 'grc': 'Greek', 'gsw': 'Swiss German', 'hi': 'Hindi',
'ind': 'Indonesian', 'ita': 'Italian', 'ja': 'Japanese', 'kn': 'Kannada',
'kas': 'Kashmiri', 'geo': 'Georgian', 'kor': 'Korean', 'lat': 'Latin',
'mar': 'Marathi', 'mni': 'Manipuri', 'mul': 'Multiple Languages', 'dut': 'Dutch',
'te': 'Telugu', 'ta': 'Tamil','cy':'Welsh'}
print("The language of the text is:", codes[detect_language(text)])
Code Explanation
- First we imported the langdetect package
- Next we created a function which takes the sentence as an argument and detects the language of the sentence using detect() function of langdetect package.
- Later we created aa dictionary which consists of langauges and their respective codes to make sure the output looks good as the detect() function is going to return the lang codes.
Output
The language of the text is: Tamil
Find More Projects
MathGenius Pro – AI-Powered Math Solver Using Python Introduction: From simple arithmetic to more complicated college-level subjects like integration, differentiation, algebra, matrices, …
CipherMaze: The Ultimate Code Cracking Quest Game Using Python Introduction: You can make CipherMaze, a fun and brain-boosting puzzle game, with Python …
Warp Perspective Using Open CV Python Introduction: In this article, we are going to see how to Create a Warp Perspective System …
Custom AI Story Generator With Emotion Control Using Python Introduction: With the help of this AI-powered story generator, users can compose stories …
AI Powered PDF Summarizer Using Python Introduction: AI-Powered PDF Summarizer is a tool that extracts and summarizes research papers from ArXiv PDFs using Ollama (Gemma 3 LLM). The …
AI Based Career Path Recommender Using Python Introduction: One of the most significant and frequently perplexing decisions in a person’s life is …