Language Detection

Introduction

This API is used to determine which language is used in the input document. It evaluates text input for each document and returns the language type.

The language detection API belongs to MT APIs. Currently, MT is in commercial use. Therefore, calling MT APIs will incur fees. You can learn about the pricing details in NLP Price Calculator.

For details about text translation endpoints, see Endpoints.

URI

  • URI format
    POST /v1/{project_id}/machine-translation/language-detection
  • Parameter description
    Table 1 URI parameters

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request

Table 2 describes the request parameters.
Table 2 Request parameters

Parameter

Type

Mandatory

Description

text

String

Yes

Text to be detected.

It is encoded using UTF-8. The text length cannot exceed 2,000 characters. Chinese characters, letters, and punctuation marks are all characters.

Table 3 Supported languages

Language

Acronym and Abbreviation

Chinese

zh

English

en

Russian

ru

Japanese

ja

German

de

French

fr

Spanish

es

Portuguese

pt

Italian

it

Turkish

tr

Arabic

ar

Korean

ko

Thai

th

Malay

ms

Vietnamese

vi

Response

Table 4 describes the response parameters.
Table 4 Response parameters

Parameter

Type

Description

detected_language

String

Calling result when the API call succeeds. It is encoded using UTF-8.

If the input text is too short or the meaning is unclear, the detection result may be inaccurate.

If the input text contains multiple languages, the language with the highest percentage is returned.

This parameter is not included when the API fails to be called.

error_code

String

Error code when the API call fails. For details, see Error Code.

The parameter is not included when the API call succeeds.

error_msg

String

Error message returned when the API fails to be called.

The parameter is not included when the API call succeeds.

Example

  • Example request
    POST https://{endpoint}/v1/{project_id}/machine-translation/language-detection
       
    Request Header:  
        Content-Type:application/json
        X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request Body:
        {
    "text": "Welcome to use the Machine Translation service."
        }  
  • Successful example response
    {
        "detected_language": "en"
    }
  • Failed example response
    {
        "error_code": "NLP.0101",
        "error_msg": "Authentication failed. Verify the token."
    }

Status Code

For details about status codes, see Status Code.

Error Code

For details about error codes, see Error Code.