mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-28 19:05:27 +02:00
checks preferred_langauge is english before translating
This commit is contained in:
parent
0616e20b6c
commit
860e457d0c
1 changed files with 14 additions and 4 deletions
|
@ -84,6 +84,7 @@ export class Agent {
|
||||||
print(translation)
|
print(translation)
|
||||||
this.bot.chat(translation+" "+this.name);
|
this.bot.chat(translation+" "+this.name);
|
||||||
this.bot.emit('finished_executing');
|
this.bot.emit('finished_executing');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startEvents();
|
this.startEvents();
|
||||||
|
@ -91,11 +92,20 @@ export class Agent {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleTranslation(message, lang) {
|
async handleTranslation(message, lang) {
|
||||||
try {
|
|
||||||
lang = String(lang); // Ensure lang is a string
|
|
||||||
|
|
||||||
const translation = await translate(message, { to: lang });
|
const preferred_lang = settings.preferred_language;
|
||||||
return translation.text || message; // Ensure translation.text is a string
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.error('Error translating message:', error);
|
console.error('Error translating message:', error);
|
||||||
return message; // Fallback to the original message if translation fails
|
return message; // Fallback to the original message if translation fails
|
||||||
|
|
Loading…
Add table
Reference in a new issue