How to Detect Text Language in Python — 55 Languages, Free API
Building a multilingual app? Routing support tickets? Filtering content by region? You need to know what language a text is written in — fast and reliably.
This guide shows how to detect text language in Python and JavaScript using a free API that supports 55+ languages and returns a confidence score.
The API: Language Detector Pro
👉 Language Detector Pro on RapidAPI
- 55+ languages including Arabic, Chinese, Japanese, Korean, Hindi
- Confidence score (0.0–1.0)
- Short text support (works on 10+ characters)
- Batch endpoint (up to 20 texts per request)
Sample Response
{
"language": "ru",
"language_name": "Russian",
"confidence": 0.97,
"alternatives": [
{"language": "uk", "confidence": 0.02},
{"language": "bg", "confidence": 0.01}
]
}
Python Example
import requests
def detect_language(text):
url = "https://language-detector-pro.p.rapidapi.com/detect"
headers = {
"X-RapidAPI-Key": "YOUR_KEY",
"Content-Type": "application/json"
}
r = requests.post(url, json={"text": text}, headers=headers)
data = r.json()
return {
"language": data["language_name"],
"code": data["language"],
"confidence": data["confidence"]
}
# Usage
texts = [
"Hello, how are you?",
"Привет, как дела?",
"Bonjour, comment allez-vous?",
"こんにちは、お元気ですか?",
"مرحبا، كيف حالك؟"
]
for text in texts:
result = detect_language(text)
print(f"{result['language']:<12} ({result['code']}) | confidence: {result['confidence']:.0%}")
Output:
English (en) | confidence: 99%
Russian (ru) | confidence: 97%
French (fr) | confidence: 98%
Japanese (ja) | confidence: 99%
Arabic (ar) | confidence: 99%
JavaScript Example
async function detectLanguage(text) {
const res = await fetch("https://language-detector-pro.p.rapidapi.com/detect", {
method: "POST",
headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({ text })
});
const data = await res.json();
console.log(`${data.language_name} (${data.language}) — ${(data.confidence * 100).toFixed(1)}%`);
return data;
}
detectLanguage("Eu falo português");
// Portuguese (pt) — 96.3%
detectLanguage("Ich spreche Deutsch");
// German (de) — 98.7%
Batch Detection
Detect language for up to 20 texts at once — perfect for routing support tickets:
import requests
tickets = [
"My order hasn't arrived",
"Mi pedido no ha llegado",
"Meine Bestellung ist nicht angekommen",
"我的订单还没有到达"
]
r = requests.post(
"https://language-detector-pro.p.rapidapi.com/batch",
json={"texts": tickets},
headers={"X-RapidAPI-Key": "YOUR_KEY", "Content-Type": "application/json"}
)
for i, item in enumerate(r.json()):
print(f"[{i}] {item['language_name']:<12} → route to {item['language'].upper()} support team")
Output:
[0] English → route to EN support team
[1] Spanish → route to ES support team
[2] German → route to DE support team
[3] Chinese → route to ZH support team
Real-World Use Cases
- Support routing — automatically assign tickets to the right language team
- Content moderation — filter content by language/region
- Chatbots — detect language before responding
- Translation pipelines — route text to the correct translation service
- SEO analysis — identify language of scraped content
Free Tier
Free tier available — no credit card required.
👉 Subscribe here: Language Detector Pro on RapidAPI
Also check out: Phone Validator Pro | Email Validator Pro
Top comments (0)