fix(glossaries): prevent translation data destruction on language selector change for multi glossaries
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m53s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m53s
This commit is contained in:
@@ -153,10 +153,12 @@ export default function GlossaryDetailPage() {
|
||||
if (i !== index) return t;
|
||||
const translations = { ...(t.translations || {}) } as Record<string, string>;
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user