- 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
This commit is contained in:
63
eveai_chat_client/static/assets/js/translation.js
Normal file
63
eveai_chat_client/static/assets/js/translation.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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');
|
||||
Reference in New Issue
Block a user