语言检测 Language Detection
自动识别文本所使用的语言,返回语言代码及置信度。支持 100+ 语言的精准识别。 Automatically identify the language of input text with confidence scores. Supports 100+ languages.
快速概览
Quick Overview
语言检测 API 基于深度学习模型,可精准识别 100+ 种语言及其变体。支持返回 top 1~5 个候选语言及置信度分数,并能自动识别文本所使用的书写系统(拉丁字母、西里尔字母、CJK 等)。建议输入至少 10 个字符以确保准确率,单次最多检测 5,000 字符。
The Language Detection API uses deep learning models to accurately identify 100+ languages and variants. Returns top 1-5 candidate languages with confidence scores, and can auto-detect the writing script (Latin, Cyrillic, CJK, etc.). Recommend at least 10 characters for accuracy; max 5,000 characters per request.
请求端点 Endpoint
POST /v1/language/detect
认证方式 Authentication
所有 API 请求均需要在 HTTP 请求头中携带有效的 API Token 进行身份认证。请在 控制台 获取您的 Access Token。
All API requests require a valid API Token in the HTTP request header for authentication. Obtain your Access Token from the Console .
Authorization: Bearer {access_token}
请求头 Request Headers
Header Header 类型 Type 必填 Required 说明 Description
Authorizationstring required Bearer Token 认证信息 Bearer token authentication
Content-Typestring required 请求体格式,固定为 application/json Request body format; fixed to application/json
请求参数 Request Parameters
参数 Parameter 类型 Type 必填 Required 说明 Description
text string required 待检测文本,建议至少 10 个字符,最长 5,000 字符 Text to detect; recommend ≥10 chars, max 5,000 chars
top_n integer optional 返回置信度最高的 N 个候选语言,默认 1,最大 5 Return top N candidates; default 1, max 5
min_confidence float optional 最低置信度阈值 0~1,低于此值的候选将被过滤,默认 0 不过滤 Minimum confidence threshold 0~1; candidates below this are filtered; default 0
return_script boolean optional 是否返回文本书写系统信息(如 Latin、Cyrillic、Han),默认 false Return writing script info (e.g. Latin, Cyrillic, Han); default false
hint_lang string optional 提供候选语言代码以提升短文本检测精度,如 zh、ja Hint language code to improve short text accuracy, e.g. zh, ja
响应字段 Response Fields
字段 Field 类型 Type 说明 Description
code integer 状态码,0 表示成功 Status code; 0 = success
message string 操作结果描述 Result description
data.detections array 检测结果列表,按置信度降序排列 Detection results, sorted by confidence descending
data.detections[].language string ISO 639-1 或 ISO 639-3 语言代码 ISO 639-1 or ISO 639-3 language code
data.detections[].language_name string 语言的英文名称 English language name
data.detections[].confidence float 置信度分数,范围 0~1,越高越可信 Confidence score 0~1; higher is more reliable
data.detections[].script string 书写系统(仅 return_script=true 时返回),如 Latin、Cyrillic、Han、Arabic、Devanagari Writing script (only when return_script=true); e.g. Latin, Cyrillic, Han, Arabic, Devanagari
data.text_length integer 输入文本的字符数 Character count of input text
支持的书写系统 Supported Scripts
书写系统 Script 代表语言 Representative Languages
Latin英语、法语、德语、西班牙语、越南语等 English, French, German, Spanish, Vietnamese, etc.
Cyrillic俄语、保加利亚语、塞尔维亚语、乌克兰语等 Russian, Bulgarian, Serbian, Ukrainian, etc.
Han中文(简体/繁体)、日文汉字 Chinese (Simplified/Traditional), Japanese Kanji
Arabic阿拉伯语、波斯语、乌尔都语 Arabic, Persian, Urdu
Devanagari印地语、尼泊尔语、马拉地语、梵语 Hindi, Nepali, Marathi, Sanskrit
Hangul韩语 Korean
Kana日语(平假名/片假名) Japanese (Hiragana/Katakana)
Thai泰语、老挝语 Thai, Lao
请求示例 Request Examples
cURL
Python
JavaScript
Go
# 基础检测:返回 Top 3 候选语言
curl -X POST https://api.itranslator.cc/v1/language/detect \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Bonjour, comment allez-vous?", "top_n": 3}'
# 短文本 + 提示语言 + 返回书写系统
curl -X POST https://api.itranslator.cc/v1/language/detect \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "今天天气真好", "top_n": 2, "hint_lang": "zh", "return_script": true, "min_confidence": 0.5}'
# 代码注释语言检测
curl -X POST https://api.itranslator.cc/v1/language/detect \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "// Diese Funktion berechnet die Summe aller Elemente im Array", "top_n": 1}'
import requests
# 基础检测
resp = requests.post(
"https://api.itranslator.cc/v1/language/detect",
headers={"Authorization": f"Bearer {token}"},
json={"text": "Bonjour, comment allez-vous?", "top_n": 3}
)
print(resp.json())
# 短文本 + 提示语言 + 返回书写系统
resp2 = requests.post(
"https://api.itranslator.cc/v1/language/detect",
headers={"Authorization": f"Bearer {token}"},
json={
"text": "今天天气真好",
"top_n": 2,
"hint_lang": "zh",
"return_script": True,
"min_confidence": 0.5
}
)
print(resp2.json())
// 基础检测
const resp = await fetch("https://api.itranslator.cc/v1/language/detect", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Bonjour, comment allez-vous?",
top_n: 3
})
});
console.log(await resp.json());
// 短文本 + 提示语言 + 书写系统
const resp2 = await fetch("https://api.itranslator.cc/v1/language/detect", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "今天天气真好",
top_n: 2,
hint_lang: "zh",
return_script: true,
min_confidence: 0.5
})
});
console.log(await resp2.json());
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
payload := map[string]interface{}{
"text": "Bonjour, comment allez-vous?",
"top_n": 3,
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST",
"https://api.itranslator.cc/v1/language/detect",
bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
fmt.Println(resp.Status)
}
响应示例 Response Examples
示例 1:基础检测(Top 3) Example 1: Basic Detection (Top 3)
{
"code": 0,
"message": "success",
"data": {
"text_length": 28,
"detections": [
{ "language": "fr", "language_name": "French", "confidence": 0.98 },
{ "language": "ca", "language_name": "Catalan", "confidence": 0.01 },
{ "language": "es", "language_name": "Spanish", "confidence": 0.01 }
]
}
}
示例 2:短文本 + 提示语言 + 书写系统 Example 2: Short Text + Hint + Script
{
"code": 0,
"message": "success",
"data": {
"text_length": 6,
"detections": [
{
"language": "zh",
"language_name": "Chinese (Simplified)",
"confidence": 0.96,
"script": "Han"
},
{
"language": "ja",
"language_name": "Japanese",
"confidence": 0.04,
"script": "Han"
}
]
}
}
示例 3:代码注释语言检测 Example 3: Code Comment Detection
{
"code": 0,
"message": "success",
"data": {
"text_length": 62,
"detections": [
{ "language": "de", "language_name": "German", "confidence": 0.99 }
]
}
}
示例 4:混合语言文本 Example 4: Mixed-language Text
{
"code": 0,
"message": "success",
"data": {
"text_length": 40,
"detections": [
{ "language": "en", "language_name": "English", "confidence": 0.75 },
{ "language": "fr", "language_name": "French", "confidence": 0.20 },
{ "language": "es", "language_name": "Spanish", "confidence": 0.05 }
]
}
}
使用限制 Usage Limits
限制项 Limit Item 上限 Cap 说明 Notes
单次文本长度 Text length 5,000 字符 chars 超出请截断或分段 Truncate or split if exceeded
最低建议字符 Min recommended chars 10 少于 10 字符时准确度下降,建议使用 hint_lang 辅助 Accuracy drops below 10 chars; use hint_lang to assist
请求频率 Rate limit 120 次/分钟 req/min 按账号计算 Per account
Top N 范围 Top N range 1 ~ 5 超出自动截断为 5 Auto-capped at 5 if exceeded
置信度解读 Confidence Interpretation
置信度范围 Confidence Range 可靠性 Reliability 建议 Recommendation
≥ 0.90 极高 Very High 可直接信任结果,无需人工复核 Trust result directly; no manual review needed
0.70 ~ 0.90 高 High 基本可靠,建议查看 Top 3 候选确认 Generally reliable; review top 3 candidates to confirm
0.50 ~ 0.70 中 Medium 文本可能过短或多语言混合,建议使用 hint_lang 重新检测 Text may be too short or mixed; retry with hint_lang
< 0.50 低 Low 不确定,可能为罕见语言或无意义文本,需人工判断 Uncertain; likely a rare language or nonsensical text; manual review required
错误码 Error Codes
HTTP Code 错误码 Error Code 说明 Description
200 0成功 Success
400 1001参数错误,请检查必填参数和参数格式 Invalid parameter; check required fields and format
400 1010text 为空或无意义字符,无法检测 Text is empty or meaningless; cannot detect
400 1011min_confidence 参数超出 0~1 范围 min_confidence out of 0~1 range
400 1012top_n 参数超出 1~5 范围 top_n out of 1~5 range
400 1013hint_lang 不是有效的语言代码 hint_lang is not a valid language code
401 2001认证失败,Token 无效或已过期 Authentication failed; invalid or expired token
403 2003无权限访问该资源 Access denied; insufficient permissions
413 3001请求文本超出长度限制(最大 5,000 字符) Text exceeds maximum length (5,000 chars)
429 4001请求频率超限,请稍后重试 Rate limit exceeded; please retry later
500 5001服务器内部错误,请重试或联系技术支持 Internal server error; retry or contact support
最佳实践 Best Practices
建议 Suggestion 说明 Description
提供足够长度的文本
Provide sufficient text
至少 10 个字符,50 个字符以上可获得最佳准确率。过短文本可能导致检测结果不稳定
At least 10 chars, 50+ for optimal accuracy. Very short text may lead to unstable results
利用 hint_lang 提升短文本检测
Use hint_lang for short text
处理短文本(<10 字符)或相似语言对(如 zh/ja、fi/et)时,通过 hint_lang 提供上下文可显著提升准确度
For short text (<10 chars) or similar language pairs (e.g. zh/ja, fi/et), providing hint_lang context significantly improves accuracy
返回 Top N 候选交叉验证
Return top N for cross-validation
将 top_n 设为 3~5,通过多个候选的置信度分布判断是否存在歧义,若首尾置信度接近则需要人工判断
Set top_n to 3-5; examine confidence distribution of candidates to detect ambiguity; if top and runner-up are close, manual review is needed
过滤低置信度结果
Filter low-confidence results
对准确度要求严格的场景设置 min_confidence=0.80,自动过滤掉不可靠的检测结果
Set min_confidence=0.80 for accuracy-critical scenarios to auto-filter unreliable results
结合书写系统信息判别
Combine with script detection
开启 return_script 获取书写系统信息,结合 script 与 language 交叉验证,区分使用相同书写系统的相似语言
Enable return_script to cross-validate script info with language detection, helping distinguish similar languages using the same script
纯文本输入,去除干扰信息
Provide clean text input
检测前移除 URL、邮箱、数字序列等非语言内容,可提高检测准确度
Remove URLs, emails, number sequences, and other non-linguistic content before detection for improved accuracy
应用场景 Use Cases
场景 Scenario 最佳方案 Approach
翻译前的自动语言检测
Pre-translation auto-detection
将 source_lang 设为 auto,后台自动调用检测接口,用户无需手动选择源语言
Set source_lang to auto; detection runs automatically, no manual language selection needed
多语言内容分类
Multi-language content classification
对用户生成内容(评论、帖子、客服消息)进行批量语言检测,按语言路由到对应的处理流程
Batch detect language of user-generated content (comments, posts, support messages) and route by language
国际化搜索引擎
International search engine
检测搜索查询的语言,自动切换到对应语言的搜索索引和排序策略
Detect search query language to auto-switch to the appropriate language index and ranking strategy
代码仓库文档语言识别
Code repository doc detection
扫描仓库中的注释和文档文件,自动识别语言分布,规划国际化文档翻译优先级
Scan comments and docs in repos to auto-identify language distribution and prioritize i18n translation
社交媒体舆情监控
Social media monitoring
实时检测社交媒体流中的文本语言,按语言分类后交由对应分析师或翻译引擎处理
Real-time language detection of social media streams, routing to language-specific analysts or translation engines
OCR 后处理语言确认
Post-OCR language verification
OCR 识别出的文本可能来源不明,通过检测接口确认后,再送入对应语言的翻译或纠错流程
OCR-extracted text may have unknown origin; confirm via detection before routing to language-specific translation or correction
与其他 API 组合使用 Combination with Other APIs
组合场景 Combo Scenario 使用方式 Approach
语言检测 + 文本翻译
Detect + Translate
先检测源语言,再将结果作为 source_lang 传入文本翻译 ,适用于未知语言输入的场景
Detect source language first, then pass result as source_lang to Text Translation for unknown-language inputs
语言检测 + 语法纠错
Detect + Grammar
检测到具体语言和变体后,传入语法纠错 ,使引擎能选择该语言专属的纠错模型
After detecting language and variant, pass to Grammar Check for language-specific correction models
语言检测 + 图片翻译
Detect + Image Translate
OCR 识别后的文本通过检测确认语言,再调用图片翻译 完成翻译
Confirm OCR-detected text language via detection, then call Image Translation for full translation
语言检测 + 语种列表
Detect + Language List
先通过语种列表 获取支持的语言代码,再传入检测获得的语言代码验证兼容性
Fetch supported language codes via Language List , then verify compatibility with detection results
使用说明
Notes
所有 API 请求均使用 HTTPS,建议开启 HTTP Keep-Alive 以提高性能。
All API requests use HTTPS; enable HTTP Keep-Alive for better performance.
请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
Do not expose your Access Token in client-side code; use a backend proxy.
推荐设置合理的超时时间(30 秒),并实现指数退避重试策略。
Set a reasonable timeout (30s) and implement exponential backoff for retries.