diff --git a/eveai_chat_client/static/assets/js/composables/useTranslation.js b/eveai_chat_client/static/assets/js/composables/useTranslation.js index e458e5a..058c9bc 100644 --- a/eveai_chat_client/static/assets/js/composables/useTranslation.js +++ b/eveai_chat_client/static/assets/js/composables/useTranslation.js @@ -167,6 +167,94 @@ export function useTranslation() { }; } +// Global cache for constants - shared across all component instances +const CONSTANTS_CACHE = { + currentLanguage: null, + translations: {} +}; + +/** + * Composable for translating application constants with global caching + * This ensures all component instances share the same cached translations + */ +export function useConstantsTranslation() { + const { translateSafe } = useTranslation(); + + /** + * Translate constants with global caching + * @param {Object} constants - Object with key-value pairs of constants to translate + * @param {string} targetLang - Target language code + * @param {Object} options - Translation options + * @returns {Promise} Object with translated constants + */ + const translateConstants = async (constants, targetLang, options = {}) => { + console.log('useConstantsTranslation: translateConstants called', { targetLang, currentCached: CONSTANTS_CACHE.currentLanguage }); + + // Check if we already have translations for this language + if (CONSTANTS_CACHE.currentLanguage === targetLang && CONSTANTS_CACHE.translations) { + console.log('useConstantsTranslation: Using cached translations for', targetLang); + return { ...CONSTANTS_CACHE.translations }; + } + + console.log('useConstantsTranslation: Translating constants to', targetLang); + + try { + const translated = {}; + + // Translate each constant + for (const [key, originalText] of Object.entries(constants)) { + translated[key] = await translateSafe(originalText, targetLang, { + context: 'constants', + fallbackText: originalText, + ...options + }); + } + + // Update global cache + CONSTANTS_CACHE.currentLanguage = targetLang; + CONSTANTS_CACHE.translations = translated; + + console.log('useConstantsTranslation: Successfully translated and cached constants'); + return translated; + } catch (error) { + console.error('useConstantsTranslation: Error translating constants:', error); + // Return original constants as fallback + return { ...constants }; + } + }; + + /** + * Get cached translations for current language + * @returns {Object|null} Cached translations or null if not available + */ + const getCachedTranslations = () => { + return CONSTANTS_CACHE.currentLanguage ? { ...CONSTANTS_CACHE.translations } : null; + }; + + /** + * Clear the constants cache (useful for testing or language reset) + */ + const clearCache = () => { + CONSTANTS_CACHE.currentLanguage = null; + CONSTANTS_CACHE.translations = {}; + console.log('useConstantsTranslation: Cache cleared'); + }; + + /** + * Get current cached language + */ + const getCachedLanguage = () => { + return CONSTANTS_CACHE.currentLanguage; + }; + + return { + translateConstants, + getCachedTranslations, + clearCache, + getCachedLanguage + }; +} + /** * Simplified composable for basic translation needs * Use this when you only need simple text translation diff --git a/eveai_chat_client/static/assets/vue-components/ChatMessage.vue b/eveai_chat_client/static/assets/vue-components/ChatMessage.vue index 33f19db..35938c9 100644 --- a/eveai_chat_client/static/assets/vue-components/ChatMessage.vue +++ b/eveai_chat_client/static/assets/vue-components/ChatMessage.vue @@ -243,6 +243,7 @@ export default { if (eventData.answer) { console.log('Updating message content with answer:', eventData.answer); this.message.content = eventData.answer; + this.message.originalContent = eventData.answer; } else { console.error('No answer in specialist-complete event data'); } diff --git a/eveai_chat_client/static/assets/vue-components/MessageHistory.vue b/eveai_chat_client/static/assets/vue-components/MessageHistory.vue index 8146462..ee570b8 100644 --- a/eveai_chat_client/static/assets/vue-components/MessageHistory.vue +++ b/eveai_chat_client/static/assets/vue-components/MessageHistory.vue @@ -145,7 +145,15 @@ export default { const firstMessage = this.messages[0]; // Controleer of we een originele inhoud hebben om te vertalen - if (firstMessage.originalContent) { + if (firstMessage.content) { + + if (!firstMessage.originalContent) { + firstMessage.originalContent = firstMessage.content; + } + + console.log('Originele inhoud van eerste AI bericht:', firstMessage.originalContent); + console.log('Content eerste AI bericht:', firstMessage.content); + console.log('Vertaling van eerste AI bericht naar:', event.detail.language); try { diff --git a/eveai_chat_client/static/assets/vue-components/ProgressTracker.vue b/eveai_chat_client/static/assets/vue-components/ProgressTracker.vue index 352cc39..c208e1e 100644 --- a/eveai_chat_client/static/assets/vue-components/ProgressTracker.vue +++ b/eveai_chat_client/static/assets/vue-components/ProgressTracker.vue @@ -22,9 +22,9 @@ āœ“ - Fout bij verwerking - Verwerking voltooid - Bezig met redeneren... + {{ errorText }} + {{ completedText }} + {{ processingText }}
{{ isExpanded ? 'ā–¼' : 'ā—„' }} @@ -53,6 +53,8 @@