Detect language API
detect_language takes a text and returns a list of the most likely languages.
It is built on top of the open-source Compact Language Detector 2 (CLD2) library.
Command name: detect_language
Success status: 200 OK
On this page
Related: Overview, Supported languages, Why WProofreader auto detect language doesn't work for small piece of texts?
Common parameters
cmd selects the command to run.
cmd
string
Yes
Must be detect_language.
These parameters work with any cmd.
serviceid
string
Cloud only
Cloud API key. Required for Cloud requests. Not used on-premises.
format
string
No
Response format. Supported: json (default), xml.
callback
string
No
JSONP wrapper function name. Use only with format=json.
See Overview for details.
Parameters
These are parameters specific to cmd=detect_language.
detect_language does not support short_answer.
text
string
Yes
Text to detect the language for.
locale
string
No
Localization for LangName. Accepted formats: es, es-ES, es_ES.
Behavior notes
localeaffects onlyLangName. It does not affect detection.If the language cannot be detected, you still get
200 OK.The response contains a single item with
LangShortCode=Unknown.
For better accuracy on long texts, split content into sentences.
Run
detect_languageper sentence.
At least 3 words in text is needed to detected the language. See the information here.
Response schema
The response contains language candidates.
Use format to switch between JSON and XML.
LangShortCode(string) Detected language code. See Supported languages. Can also beUnknown.LangName(string) Human-readable language name. Localized usinglocalewhen provided.Proportion(number) Confidence / proportion of this language in the text. Higher means “more likely”.
Request examples
Example: single language detected
Request:
Response (200 OK):
Example: localized language name (locale=es-ES)
Request:
Response (200 OK):
Example: no language detected
Request:
Response (200 OK):
Errors
This command has no command-specific 4xx errors.
When language detection fails, the response is still 200 OK with LangShortCode=Unknown.
Common API errors (for example an invalid serviceid) use the shared error format from Overview.
Was this helpful?

