Have an online platform you’re looking to increase your international clientele on? Establishing a solid language translation system should be one of your first steps. In this brief tutorial, we will demonstrate how you can use a Natural Language Processing API in C/C++ to instantly determine which language a text string is written in, putting you in a good spot for the full language translation step.
To begin, we will Install libcurl in our C/C++ project:
Now, we can input our text string and API key into the following example code to call the function:
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/nlp-v2/language/detect");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "textToDetect=%3Cstring%3E";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
This will supply the language name as well as the three-letter code associated with the language; 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), Chinese (ZHO).