I'm trying to set up a function in which detects the language of the text sample (through AWS API) but I get in nodeJs I get undefined.
const fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.update({ region: 'eu-west-1' });
function languageDetection(test) {
const params = { TextList: [test] };
var comprehend = new AWS.Comprehend();
comprehend.batchDetectDominantLanguage(params, function (err, data) {
if (err) console.log(err, err.stack);
else {
const { ResultList } = data;
const languages = ResultList[0]["Languages"];
const detectedLanguage = languages[0]
const detectedLanguageText = detectedLanguage["LanguageCode"];
return detectedLanguageText
}
});
}
let aTextExample = 'This is a sample text'
const language = languageDetection(aTextExample)
console.log(language)