plainheart / bing-translate-api

A simple and free API for Bing & Microsoft Translator for Node.js
https://github.com/plainheart/bing-translate-api
MIT License
161 stars 28 forks source link

fix: avoid throwing error when `detectedLang` is not present #39

Closed qixiaobo closed 5 months ago

qixiaobo commented 5 months ago

We know that not in all scenarios bing will return the detectedLang field, which needs to be handled in a compatible manner.

Please refer to https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-translate

A successful response is a JSON array with one result for each string in the input array. A result object includes the following properties:

detectedLanguage: An object describing the detected language through the following properties:

language: A string representing the code of the detected language.

score: A float value indicating the confidence in the result. The score is between zero and one and a low score indicates a low confidence.

The detectedLanguage property is only present in the result object when language autodetection is requested.