Language Identification

Updated at:

Introduction

Automatically identifies the language of input text and returns the corresponding ISO language code. Aidge's Language Identification is optimized for short e-commerce texts, such as product titles, search queries, and customer service chats. It is highly robust when processing texts that contain a mix of numbers, abbreviations, and brand names.

It covers 31 languages for query phrases and 35 languages for general scenarios, and supports synchronous calls.

Use cases:

  • Search query routing: Route queries in multiple languages to the appropriate search engine after identification.

  • Customer service routing: Automatically route incoming conversations to customer service agents or translation bots based on the visitor's language.

  • Pre-translation check: Identify the source language before calling the Text Translation service.

  • Multilingual content classification: Group mixed-language content, such as product reviews or descriptions, by language for subsequent semantic analysis.

Quick start

Request parameters

Parameter

Type

Required

Description

SourceText

String

Yes

The source text to identify. For short texts such as titles or search queries, accuracy is generally stable for text longer than five characters. Identification may be unreliable for extremely short texts or those containing only symbols or numbers.

Scene

String

No

The default value is common. If you are identifying a search phrase, set this parameter to query. If you pass an incorrect value or omit this parameter, the service defaults to the common model. Note: The value query must be in lowercase.

Response fields

Field

Type

Description

Code

String

The business status code. A value of Success indicates that the request is successful, and other values are named error codes.

Success

Boolean

Indicates whether the call was successful.

RequestId

String

The unique request ID.

Message

String

The error message, returned only when the request fails.

Data.DetectedLanguage

String

The detected language code. For a list of supported languages, see the "Supported languages" section.

Data.UsageMap.InputCharacterCount

Number

The number of characters in the input text, used for billing verification.

Examples

Request example

{
  "SourceText": "This is a test",
  "Scene": "query"   
}

Response example

{
  "Code": "success",
  "Message": "Success",
  "Success": true,
  "RequestId": "2157065A-D6C8-1F3E-A4D0-B1234567890",
  "Data": {
    "DetectedLanguage": "en",
    "UsageMap": { "InputCharacterCount": 14 }
  }
}

Supported languages

The service supports 31 languages for query phrases and 35 languages for general scenarios. For a complete list of languages and their codes, see the "Supported Languages for Language Identification" section in Language Pair Mapping.

Best practices

  • Avoid unnecessary translations: Before you call the Text Translation service, identify the source language. If the DetectedLanguage is the same as your target language, you can skip the translation step.

  • Handle short text: For texts with three or fewer characters, or those that consist entirely of numbers or symbols, create an allowlist on the client side to bypass identification and fall back to a default language.

  • Distinguishing between Simplified and Traditional Chinese: This API can distinguish between zh and zh-tw. If your downstream translation model does not support zh-tw, you must perform the mapping on the client.

  • Handle mixed-language text: The service returns the dominant language, which is the language with the largest proportion in the text. If you need to identify the language of each sentence, split the text into sentences on the client side and call the service for each sentence.

Error codes

Error code

Description

InvalidParameter

SourceText is empty or exceeds the length limit.

InputContentBlocked

The input text triggered content moderation.

FreeQuotaExhausted

The free trial quota has been exhausted.

InternalError

Internal server error. Please save the RequestId and contact technical support.

For a complete list of error codes, see Error Codes.

Limitations

  • Call mode: Synchronous. For details on queries-per-second (QPS) limits and timeout settings, see the documentation on rate limiting.

  • Billing: Charged by InputCharacterCount (number of characters). For more information, see Billing for Translation Services.

Next steps