Running code sample shown on Azure AI Translate website, but the response is not the same. It detects the wrong language

Tee Uttamavanit 0 Reputation points
2025-04-24T03:34:32.8433333+00:00

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?

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
488 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JAYA SHANKAR G S 2,355 Reputation points Microsoft External Staff
    2025-04-30T11:54:30.3366667+00:00

    Hello @Tee Uttamavanit ,

    Got updates from product team, sorry of the inconvenience that Swahili is not supported for language auto-detection in the Translator service, the documentation will be reviewed and updated accordingly to reflect the correct support status.

    Workaround would be to use the language code explicitly in from parameter.

    params.append("from", "sw");
    

    Thank you

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.