From 36aeac2c5e13010801c03d0fc45e8a538b26229f Mon Sep 17 00:00:00 2001 From: sepehr Date: Sun, 28 Jun 2026 11:03:31 +0200 Subject: [PATCH] fix(glossaries): prevent translation data destruction on language selector change for multi glossaries --- .../app/dashboard/glossaries/[id]/page.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/dashboard/glossaries/[id]/page.tsx b/frontend/src/app/dashboard/glossaries/[id]/page.tsx index 322a41c..83674a2 100644 --- a/frontend/src/app/dashboard/glossaries/[id]/page.tsx +++ b/frontend/src/app/dashboard/glossaries/[id]/page.tsx @@ -153,10 +153,12 @@ export default function GlossaryDetailPage() { if (i !== index) return t; const translations = { ...(t.translations || {}) } as Record; - const editLang = field === 'source' ? sourceLanguage : targetLanguage; + const editLang = (field === 'source' ? sourceLanguage : targetLanguage).toLowerCase(); + const srcLang = glossary.source_language.toLowerCase(); + const tgtLang = glossary.target_language.toLowerCase(); if (field === 'source') { - if (editLang === glossary.source_language) { + if (editLang === srcLang) { return { ...t, source: value }; } else { if (editLang && editLang !== 'multi') { @@ -165,7 +167,7 @@ export default function GlossaryDetailPage() { return { ...t, translations }; } } else { - if (editLang === 'multi' || editLang === glossary.target_language) { + if (editLang === 'multi' || editLang === tgtLang) { return { ...t, target: value }; } else { if (editLang && editLang !== 'multi') { @@ -215,12 +217,24 @@ export default function GlossaryDetailPage() { }; const handleSourceLanguageChange = (newLang: string) => { + // For multilingual glossaries, the selector is a VIEW filter only. + // migrateTerms must not be called — it would destroy translation data. + if (!glossary || glossary.target_language === 'multi') { + setSourceLanguage(newLang); + return; + } const updated = migrateTerms(terms, sourceLanguage, newLang, targetLanguage, targetLanguage); setSourceLanguage(newLang); setTerms(updated); }; const handleTargetLanguageChange = (newLang: string) => { + // For multilingual glossaries, the selector is a VIEW filter only. + // migrateTerms must not be called — it would destroy translation data. + if (!glossary || glossary.target_language === 'multi') { + setTargetLanguage(newLang); + return; + } const updated = migrateTerms(terms, sourceLanguage, sourceLanguage, targetLanguage, newLang); setTargetLanguage(newLang); setTerms(updated);