Files
eveAI/eveai_chat_client/static/assets/js/translation.js
Josako fbc9f44ac8 - Translations completed for Front-End, Configs (e.g. Forms) and free text.
- Allowed_languages and default_language now part of Tenant Make iso Tenant
- Introduction of Translation into Traicie Selection Specialist
2025-06-30 14:20:17 +02:00

64 lines
2.2 KiB
JavaScript

/**
* EveAI Vertaal API Client
* Functies voor het vertalen van tekst via de EveAI API
*/
const TranslationClient = {
/**
* Vertaalt een tekst naar de opgegeven doeltaal
*
* @param {string} text - De te vertalen tekst
* @param {string} targetLang - ISO 639-1 taalcode van de doeltaal
* @param {string|null} sourceLang - (Optioneel) ISO 639-1 taalcode van de brontaal
* @param {string|null} context - (Optioneel) Context voor de vertaling
* @param {string|null} apiPrefix - (Optioneel) API prefix voor tenant routing
* @returns {Promise<object>} - Een promise met het vertaalresultaat
*/
translate: async function(text, targetLang, sourceLang = null, context = null, apiPrefix = '') {
try {
// Voorbereiding van de aanvraagdata
const requestData = {
text: text,
target_lang: targetLang
};
// Voeg optionele parameters toe indien aanwezig
if (sourceLang) requestData.source_lang = sourceLang;
if (context) requestData.context = context;
// Bouw de juiste endpoint URL met prefix
const endpoint = `${apiPrefix}/chat/api/translate`;
console.log(`Vertaling aanvragen op endpoint: ${endpoint}`);
// Doe het API-verzoek
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestData)
});
// Controleer of het verzoek succesvol was
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Onbekende fout bij vertalen');
}
// Verwerk het resultaat
return await response.json();
} catch (error) {
console.error('Vertaalfout:', error);
throw error;
}
}
};
// Maak TranslationClient globaal beschikbaar
window.TranslationClient = TranslationClient;
// Geen auto-initialisatie meer nodig
// De Vue-based LanguageSelector component neemt deze taak over
console.log('TranslationClient geladen en klaar voor gebruik');