async function set_translated_transcript()

in lambda/fulfillment/lib/middleware/multilanguage.js [103:132]


async function set_translated_transcript(locale, req) {
    const SessionAttributes = _.get(req, 'session');
    const detectedLocale = SessionAttributes.userDetectedLocale;
    const detectedSecondaryLocale = SessionAttributes.userDetectedSecondaryLocale;

    if ( ! req.question.toLowerCase().startsWith("qid::")) {
        if (locale === 'en' && detectedLocale === 'en' && detectedSecondaryLocale === undefined) {
            qnabot.log("No translation - english detected");
        } else if (locale === 'en' && detectedLocale === 'en' && detectedSecondaryLocale) {
            qnabot.log("translate to english using secondary detected locale:  ", req.question);
            const translation = await get_translation(req.question, detectedSecondaryLocale, 'en',req);

            _.set(req, "_translation", translation);
            _.set(req, "question", translation);
            qnabot.log("Overriding input question with translation: ", req.question);
        }  else if (locale !== '' && locale.charAt(0) !== '%' && detectedLocale && detectedLocale !== '') {
            qnabot.log("Confidence in the detected language high enough.");
            const translation = await get_translation(req.question, detectedLocale, 'en',req);

            _.set(req, "_translation", translation);
            _.set(req, "question", translation);
            qnabot.log("Overriding input question with translation: ", req.question);
        }  else {
            qnabot.log ('not possible to perform language translation')
        }
    } else {
        qnabot.log("Question targeting specified Qid (starts with QID::) - skip translation");
    }

}