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;
|
if (i !== index) return t;
|
||||||
const translations = { ...(t.translations || {}) } as Record<string, string>;
|
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 (field === 'source') {
|
||||||
if (editLang === glossary.source_language) {
|
if (editLang === srcLang) {
|
||||||
return { ...t, source: value };
|
return { ...t, source: value };
|
||||||
} else {
|
} else {
|
||||||
if (editLang && editLang !== 'multi') {
|
if (editLang && editLang !== 'multi') {
|
||||||
@@ -165,7 +167,7 @@ export default function GlossaryDetailPage() {
|
|||||||
return { ...t, translations };
|
return { ...t, translations };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (editLang === 'multi' || editLang === glossary.target_language) {
|
if (editLang === 'multi' || editLang === tgtLang) {
|
||||||
return { ...t, target: value };
|
return { ...t, target: value };
|
||||||
} else {
|
} else {
|
||||||
if (editLang && editLang !== 'multi') {
|
if (editLang && editLang !== 'multi') {
|
||||||
@@ -215,12 +217,24 @@ export default function GlossaryDetailPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSourceLanguageChange = (newLang: string) => {
|
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);
|
const updated = migrateTerms(terms, sourceLanguage, newLang, targetLanguage, targetLanguage);
|
||||||
setSourceLanguage(newLang);
|
setSourceLanguage(newLang);
|
||||||
setTerms(updated);
|
setTerms(updated);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTargetLanguageChange = (newLang: string) => {
|
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);
|
const updated = migrateTerms(terms, sourceLanguage, sourceLanguage, targetLanguage, newLang);
|
||||||
setTargetLanguage(newLang);
|
setTargetLanguage(newLang);
|
||||||
setTerms(updated);
|
setTerms(updated);
|
||||||
|
|||||||
Reference in New Issue
Block a user