Language Detection API
Text AnalysisDetectLanguage API: A Powerful Tool for Language Detection
DetectLanguage is a public API that is designed to provide language detection services for text. This API can detect more than 70 languages from a given text input. It is useful especially for businesses that need to automate language identification to run analytics, for content translation, or routing of customer support queries to language-specific service desks.
Getting Started
To use the DetectLanguage API, you need to first sign up to create an account. After signing up, you will receive an API key which you will use in your requests.
API Endpoint
The API endpoint URL is https://ws.detectlanguage.com/0.2/detect
. You will use this URL to send your requests to the API.
Sending a Request
You need to send your request to the API endpoint using the POST
method and set the Authorization
header to your API key. The text to be analysed should be sent in the request body.
Here is a sample request in JavaScript:
const text = 'This is a sample text to test language detection using DetectLanguage API';
const apiKey = 'YOUR_API_KEY';
const request = {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({q: text})
};
fetch('https://ws.detectlanguage.com/0.2/detect', request)
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.error(err);
});
In the above example, we are using the Fetch API to send a POST request to the DetectLanguage API. We pass the request body as a JSON object containing a q
property that holds the text to be analysed.
Response
The API response contains the detected language code and score for each of the detected languages.
Here is a sample response in JSON:
{
"data": {
"detections": [
{
"language": "en",
"isReliable": true,
"confidence": 16.76
},
{
"language": "id",
"isReliable": true,
"confidence": 3.14
}
]
}
}
In the above response, we have two detected languages - English with a confidence score of 16.76 and Indonesian with a confidence score of 3.14.
Conclusion
In conclusion, the DetectLanguage API is a powerful tool that can be used for effective language detection in various business applications. With its ease of use and high accuracy, it is a must-have for any business that needs to handle multilingual content.