From 860e457d0c090fde3377be63bcdb72995b14552c Mon Sep 17 00:00:00 2001 From: Vineeth <94882582+FantomWolf182@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:35:49 -0500 Subject: [PATCH] checks preferred_langauge is english before translating --- src/agent/agent.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/agent/agent.js b/src/agent/agent.js index 367498f..e9b9ad9 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -84,6 +84,7 @@ export class Agent { print(translation) this.bot.chat(translation+" "+this.name); this.bot.emit('finished_executing'); + } this.startEvents(); @@ -91,11 +92,20 @@ export class Agent { } async handleTranslation(message, lang) { - try { - lang = String(lang); // Ensure lang is a string - const translation = await translate(message, { to: lang }); - return translation.text || message; // Ensure translation.text is a string + const preferred_lang = settings.preferred_language; + + try { + if (preferred_lang.toLowerCase() == "en" || preferred_lang.toLowerCase() == "english"){ + return message; + } + else{ + lang = String(lang); // Ensure lang is a string + + const translation = await translate(message, { to: lang }); + return translation.text || message; // Ensure translation.text is a string + } + } catch (error) { console.error('Error translating message:', error); return message; // Fallback to the original message if translation fails