I tried running the example found on the Azure website on the following URL:
https://learn.microsoft.com/en-us/azure/ai-services/translator/text-translation/how-to/use-rest-api?tabs=nodejs#detect-source-language-during-translation
The example is under the "Detect source language during translation" section. However, the request does not get the expected response.
Here is my code:
let params = new URLSearchParams();
params.append("api-version", "3.0");
params.append("category", "general");
params.append("to", "en");
params.append("to", "it");
axios({
baseURL: "https://api.cognitive.microsofttranslator.com",
url: '/translate',
method: 'post',
headers: {
'Ocp-Apim-Subscription-Key': key,
// location required if you're using a multi-service or regional (not global) resource.
//'Ocp-Apim-Subscription-Region': location,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
params: params,
data: [{
'text': 'Halo, rafiki! Ulifanya nini leo?'
}],
responseType: 'json'
}).then(function (response) {
console.log(JSON.stringify(response.data, null, 4));
})
Here is the response I get:
[
{
"detectedLanguage": {
"language": "en",
"score": 1
},
"translations": [
{
"text": "Halo, rafiki! Ulifanya nini leo?",
"to": "en"
},
{
"text": "Aureola, rafiki! Ulifanya nini leo?",
"to": "it"
}
]
}
]
I tried changing setting the value for "category" parameter to "general" or "generalnn" but still getting the same response as above. Please note that the code I run is the same as the one shown in the example in the give URL above.
My question is what are we doing wrong? Could anyone advise us?