How to Detect Language of Text in JavaScript
If you want your website to be successful on a global scale, ensuring you have an accessible interface for users across the world is an essential element. To create this universal experience within your online platform, providing language translation technology will stimulate a better customer experience and promote inclusivity across the board. By utilizing the following API to detect languages, you will be able to simplify and speed up the translation process.
First, we will install the jQery library:
bower install jquery
At this point, we are ready to perform the conversion by inputting the target text string into the below example code:
var settings = {
"url": "https://api.cloudmersive.com/nlp-v2/language/detect",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": {
"textToDetect": "<string>"
}
};$.ajax(settings).done(function (response) {
console.log(response);
});
This will provide support for the following languages: Supports Danish (DAN), German (DEU), English (ENG), French (FRA), Italian (ITA), Japanese (JPN), Korean (KOR), Dutch (NLD), Norwegian (NOR), Portuguese (POR), Russian (RUS), Spanish (SPA), Swedish (SWE), and Chinese (ZHO).