mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-24 08:55:23 +02:00
Add files via upload
This commit is contained in:
parent
0bac79e8aa
commit
4165fe2d35
1 changed files with 32 additions and 0 deletions
32
src/agent/translator.js
Normal file
32
src/agent/translator.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import translate from 'google-translate-api-x';
|
||||
import settings from '../../settings.js';
|
||||
|
||||
|
||||
const preferred_lang = settings.language;
|
||||
|
||||
|
||||
export async function handleTranslation(message) {
|
||||
try {
|
||||
if (preferred_lang.toLowerCase() === 'en' || preferred_lang.toLowerCase() === 'english') {
|
||||
return message;
|
||||
} else {
|
||||
const lang = String(preferred_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
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleEnglishTranslation(message) {
|
||||
try {
|
||||
const translation = await translate(message, { to: 'english' });
|
||||
return translation.text || message; // Ensures translation.text is a string
|
||||
} catch (error) {
|
||||
console.error('Error translating message:', error);
|
||||
return message; // Fallback to the original message if translation fails
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue