diff --git a/html/kidsai/script-new.js b/html/kidsai/script-new.js index 55ce6bc..f1137bf 100644 --- a/html/kidsai/script-new.js +++ b/html/kidsai/script-new.js @@ -143,6 +143,18 @@ class KidsAIExplorer { } } + // Helper method to get translation for a key + getTranslation(key) { + try { + if (typeof translations !== 'undefined' && translations[this.currentLanguage]) { + return translations[this.currentLanguage][key]; + } + } catch (error) { + console.warn('⚠️ Could not get translation for key:', key); + } + return null; + } + switchLanguage(lang) { console.log('🔄 Switching language to:', lang); this.currentLanguage = lang; @@ -158,7 +170,8 @@ class KidsAIExplorer { if (!question) { console.log('⚠️ No question provided'); - this.showMessage('Please ask me something first! 🤔', 'warning'); + const message = this.getTranslation('ask-something-first') || 'Please ask me something first! 🤔'; + this.showMessage(message, 'warning'); return; } @@ -194,7 +207,8 @@ class KidsAIExplorer { } catch (error) { console.error('❌ Error getting AI guidance:', error); - this.showMessage('Sorry, I had trouble processing your question. Let me give you some thinking guidance instead!', 'info'); + const message = this.getTranslation('processing-trouble') || 'Sorry, I had trouble processing your question. Let me give you some thinking guidance instead!'; + this.showMessage(message, 'info'); this.displayLocalGuidance(question); } finally { this.hideLoading(); @@ -227,15 +241,20 @@ class KidsAIExplorer { // Show initial encouragement const welcomeStep = document.createElement('div'); welcomeStep.className = 'conversation-step visible'; + + // Get translated messages + const encouragementText = guidance.encouragement || this.getTranslation('default-encouragement') || "Great question! Let's explore this together step by step! 🚀"; + const detectiveHelpText = this.getTranslation('detective-help') || "Instead of giving you the answer right away, I'll help you think through this like a detective! 🕵️"; + welcomeStep.innerHTML = `
`; @@ -263,7 +282,8 @@ class KidsAIExplorer { displayLocalGuidance(question) { console.log('📚 Displaying local guidance for:', question); - const encouragements = [ + // Get translated encouragements or use fallback + const encouragements = this.getTranslation('encouragements') || [ "Great question! You're thinking like a real scientist! 🔬", "Wow, that's a fantastic thing to wonder about! 🌟", "I love how curious you are! That's how great discoveries happen! 🚀" @@ -271,13 +291,16 @@ class KidsAIExplorer { const randomEncouragement = encouragements[Math.floor(Math.random() * encouragements.length)]; + // Get translated fallback questions + const fallbackQuestions = [ + this.getTranslation('fallback-question-1') || "What do you already know about this topic?", + this.getTranslation('fallback-question-2') || "What do you think might be the reason for this?", + this.getTranslation('fallback-question-3') || "Where could you look to find more information?", + this.getTranslation('fallback-question-4') || "Can you think of any examples or similar situations?" + ]; + this.displayGuidance({ - questions: [ - "What do you already know about this topic?", - "What do you think might be the reason for this?", - "Where could you look to find more information?", - "Can you think of any examples or similar situations?" - ], + questions: fallbackQuestions, encouragement: randomEncouragement }); } @@ -340,10 +363,8 @@ class KidsAIExplorer { const answer = textarea.value.trim(); if (!answer) { - this.showMessage( - this.currentLanguage === 'de' ? 'Bitte schreibe deine Gedanken auf! 🤔' : 'Please write down your thoughts! 🤔', - 'warning' - ); + const message = this.getTranslation('write-thoughts') || 'Please write down your thoughts! 🤔'; + this.showMessage(message, 'warning'); return; } @@ -368,10 +389,10 @@ class KidsAIExplorer {