diff --git a/frontend/src/i18n/locales/de/socialnetwork.json b/frontend/src/i18n/locales/de/socialnetwork.json index 03a7631..eeccab9 100644 --- a/frontend/src/i18n/locales/de/socialnetwork.json +++ b/frontend/src/i18n/locales/de/socialnetwork.json @@ -457,8 +457,8 @@ "vocabTrainerDescription": "Übe die wichtigsten Begriffe dieser Lektion interaktiv.", "startVocabTrainer": "Vokabeltrainer starten", "stopTrainer": "Trainer beenden", - "translateTo": "Übersetze ins Deutsche", - "translateFrom": "Übersetze ins Bisaya", + "translateTo": "Übersetze ins Bisaya", + "translateFrom": "Übersetze ins Deutsche", "next": "Weiter", "totalAttempts": "Versuche", "successRate": "Erfolgsrate", diff --git a/frontend/src/i18n/locales/en/socialnetwork.json b/frontend/src/i18n/locales/en/socialnetwork.json index 76a6145..30a386f 100644 --- a/frontend/src/i18n/locales/en/socialnetwork.json +++ b/frontend/src/i18n/locales/en/socialnetwork.json @@ -457,8 +457,8 @@ "vocabTrainerDescription": "Practice the most important terms of this lesson interactively.", "startVocabTrainer": "Start Vocabulary Trainer", "stopTrainer": "Stop Trainer", - "translateTo": "Translate to English", - "translateFrom": "Translate to Target Language", + "translateTo": "Translate into Bisaya", + "translateFrom": "Translate into German", "next": "Next", "totalAttempts": "Attempts", "successRate": "Success Rate", diff --git a/frontend/src/i18n/locales/es/socialnetwork.json b/frontend/src/i18n/locales/es/socialnetwork.json index 3ee432d..138f3ac 100644 --- a/frontend/src/i18n/locales/es/socialnetwork.json +++ b/frontend/src/i18n/locales/es/socialnetwork.json @@ -455,8 +455,8 @@ "vocabTrainerDescription": "Practica los términos clave de esta lección de forma interactiva.", "startVocabTrainer": "Iniciar entrenador", "stopTrainer": "Detener entrenador", - "translateTo": "Traduce al alemán", - "translateFrom": "Traduce desde bisaya", + "translateTo": "Traduce al bisaya", + "translateFrom": "Traduce al alemán", "next": "Siguiente", "totalAttempts": "Intentos", "successRate": "Tasa de acierto", diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index 3a2fd28..ae65394 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -1699,49 +1699,43 @@ export default { return matches; }, - buildChoiceOptions(correctAnswers, allVocabs, excludePrompt = null) { + /** + * @param {'L2R'|'R2L'} direction L2R: Antwort = reference (Zielsprache, z. B. Bisaya). R2L: Antwort = learning (Muttersprache, z. B. Deutsch). + * Distraktoren kommen immer nur aus derselben Sprache wie die richtige Antwort. + */ + buildChoiceOptions(correctAnswers, allVocabs, excludePrompt = null, direction = 'L2R') { const normalizedCorrectAnswers = Array.isArray(correctAnswers) ? correctAnswers : [correctAnswers]; const options = new Set(normalizedCorrectAnswers.filter(Boolean)); - // Normalisiere alle Werte für den Vergleich (trim + lowercase) const normalizedExcludeSet = new Set(); normalizedCorrectAnswers.forEach((answer) => { normalizedExcludeSet.add(this.normalizeVocab(answer)); }); - // Wichtig: Der Prompt (die Frage) darf nicht in den Optionen erscheinen if (excludePrompt) { normalizedExcludeSet.add(this.normalizeVocab(excludePrompt)); } - - // Sammle alle verfügbaren Distraktoren aus beiden Richtungen + + const answerField = direction === 'L2R' ? 'reference' : 'learning'; + const allDistractors = []; - allVocabs.forEach(vocab => { - // Füge beide Richtungen hinzu (learning und reference) - if (vocab.learning && vocab.learning.trim()) { - const normalized = this.normalizeVocab(vocab.learning); - if (!normalizedExcludeSet.has(normalized)) { - allDistractors.push(vocab.learning); - } - } - if (vocab.reference && vocab.reference.trim()) { - const normalized = this.normalizeVocab(vocab.reference); - if (!normalizedExcludeSet.has(normalized)) { - allDistractors.push(vocab.reference); - } + allVocabs.forEach((vocab) => { + const candidate = vocab[answerField]; + if (!candidate || !candidate.trim()) return; + const normalized = this.normalizeVocab(candidate); + if (!normalizedExcludeSet.has(normalized)) { + allDistractors.push(candidate); } }); - - // Entferne Duplikate + const uniqueDistractors = [...new Set(allDistractors)]; - - // Füge Distraktoren hinzu, bis wir 4 Optionen haben + let attempts = 0; const maxAttempts = 200; - + while (options.size < 4 && uniqueDistractors.length > 0 && attempts < maxAttempts) { attempts++; const randomIndex = Math.floor(Math.random() * uniqueDistractors.length); const distractor = uniqueDistractors[randomIndex]; - + if (distractor && distractor.trim()) { const normalizedDistractor = this.normalizeVocab(distractor); if (!normalizedExcludeSet.has(normalizedDistractor) && !options.has(distractor)) { @@ -1749,18 +1743,15 @@ export default { } } } - - // Falls immer noch nicht genug Optionen: Verwende auch die andere Richtung der aktuellen Vokabeln + if (options.size < 4 && allVocabs.length > 0) { - allVocabs.forEach(vocab => { + allVocabs.forEach((vocab) => { if (options.size >= 4) return; - - // Verwende die andere Richtung als Distraktor - const otherDirection = this.vocabTrainerDirection === 'L2R' ? vocab.learning : vocab.reference; - if (otherDirection && otherDirection.trim()) { - const normalized = this.normalizeVocab(otherDirection); - if (!normalizedExcludeSet.has(normalized) && !options.has(otherDirection)) { - options.add(otherDirection); + const candidate = vocab[answerField]; + if (candidate && candidate.trim()) { + const normalized = this.normalizeVocab(candidate); + if (!normalizedExcludeSet.has(normalized) && !options.has(candidate)) { + options.add(candidate); } } }); @@ -1845,9 +1836,10 @@ export default { debugLog('[VocabLessonView] Answer:', this.currentVocabQuestion.answer); // Wichtig: Der Prompt (die Frage) darf nicht in den Optionen erscheinen this.vocabTrainerChoiceOptions = this.buildChoiceOptions( - this.currentVocabQuestion.answers, + this.currentVocabQuestion.answers, allTrainerVocabs, - this.currentVocabQuestion.prompt // Exkludiere den Prompt + this.currentVocabQuestion.prompt, + this.vocabTrainerDirection ); debugLog('[VocabLessonView] Choice-Optionen erstellt:', this.vocabTrainerChoiceOptions); }