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)arrow-up-right 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.

Name
Type
Required
Description

cmd

string

Yes

Must be detect_language.

These parameters work with any cmd.

Name
Type
Required
Description

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.

circle-exclamation
Name
Type
Required
Description

text

string

Yes

Text to detect the language for.

locale

string

No

Localization for LangName. Accepted formats: es, es-ES, es_ES.

Behavior notes

  • locale affects only LangName. 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_language per 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 be Unknown.

  • LangName (string) Human-readable language name. Localized using locale when 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.

Last updated

Was this helpful?