diff --git a/apps/ba-online-toolbox/src/tools/ScenarioEditor/components/TranslationPane.vue b/apps/ba-online-toolbox/src/tools/ScenarioEditor/components/TranslationPane.vue index 3df60c48..ef9f5a49 100644 --- a/apps/ba-online-toolbox/src/tools/ScenarioEditor/components/TranslationPane.vue +++ b/apps/ba-online-toolbox/src/tools/ScenarioEditor/components/TranslationPane.vue @@ -97,7 +97,9 @@ 规范符号 - 重新翻译 + 重新翻译 @@ -226,11 +228,16 @@ const langSelect = [ { label: "泰语", key: "TextTh" }, ]; -const translateHandle = () => { +const currentText = computed(() => { + return mainStore.getScenario.content[config.getSelectLine]?.[ + config.getLanguage + ]; +}); + +const translateHandle = (force = false) => { + if (!force && config.getTmpMachineTranslate(currentText.value)) return; if (config.getSelectLine !== -1) { - const text = mainStore.getScenario.content[config.getSelectLine][ - config.getLanguage - ] + const text = currentText.value ?.replaceAll("#n", "[#n]") ?.replaceAll(/\[.*?\]/g, ""); translate( @@ -240,6 +247,7 @@ const translateHandle = () => { ) .then(res => { config.setTmpMachineTranslate( + currentText.value, halfToFull((res.translation || [])[0] ?? "") ); }) @@ -252,7 +260,9 @@ const translateHandle = () => { const acceptHandle = () => { if (config.getSelectLine !== -1) { const line = mainStore.getScenario.content[config.getSelectLine]; - line[config.getTargetLang] = config.tmpMachineTranslate; + line[config.getTargetLang] = config.getTmpMachineTranslate( + currentText.value + ); mainStore.setContentLine(line as ContentLine, config.getSelectLine); } }; @@ -314,7 +324,10 @@ function handleLLMTranslateRequest() { fullWidthText, studentNames.value ); - config.setTmpMachineTranslate(formalizeQuotation(studentTransformed)); + config.setTmpMachineTranslate( + currentText.value, + formalizeQuotation(studentTransformed) + ); }) .catch(err => { console.log(err); diff --git a/apps/ba-online-toolbox/src/tools/ScenarioEditor/store/configStore.ts b/apps/ba-online-toolbox/src/tools/ScenarioEditor/store/configStore.ts index 0f6dbd31..f52054ec 100644 --- a/apps/ba-online-toolbox/src/tools/ScenarioEditor/store/configStore.ts +++ b/apps/ba-online-toolbox/src/tools/ScenarioEditor/store/configStore.ts @@ -10,7 +10,7 @@ export const useGlobalConfig = defineStore({ selectLine: 0, language: "TextJp" as Language, targetLang: "TextCn" as Language, - tmpMachineTranslate: "", + tmpMachineTranslate: {} as { [key: string]: string }, switchLanguage: 0b11, showAllLanguage: true, selectTag: "[wa:]", @@ -22,7 +22,23 @@ export const useGlobalConfig = defineStore({ getSelectLine: state => state.selectLine, getLanguage: state => state.language, getTargetLang: state => state.targetLang, - getTmpMachineTranslate: state => state.tmpMachineTranslate, + /* eslint-disable indent */ + getTmpMachineTranslate: + state => + (query = "") => { + const objectType = Object.prototype.toString.call( + state.tmpMachineTranslate + ); + switch (objectType) { + case "[object Object]": + return state.tmpMachineTranslate?.[query] || undefined; + case "[object String]": + return state.tmpMachineTranslate; + default: + return ""; + } + }, + /* eslint-enable indent */ isSwitchLanguage: state => state.switchLanguage, getSelectTag: state => state.selectTag, getShowAllLanguage: state => state.showAllLanguage, @@ -51,10 +67,13 @@ export const useGlobalConfig = defineStore({ }, setSelectLine(line: number) { this.selectLine = line; - this.tmpMachineTranslate = ""; }, - setTmpMachineTranslate(text: string) { - this.tmpMachineTranslate = text; + setTmpMachineTranslate(origin: string, text: string) { + const mapType = Object.prototype.toString.call(this.tmpMachineTranslate); + if (mapType !== "[object Object]") { + this.tmpMachineTranslate = {}; + } + this.tmpMachineTranslate[origin] = text; }, setLanguage(language: Language) { this.language = language; @@ -65,7 +84,6 @@ export const useGlobalConfig = defineStore({ initialize_state() { this.proofread = false; this.selectLine = -1; - this.tmpMachineTranslate = ""; this.previewMode = false; }, initialize_config() { @@ -82,6 +100,9 @@ export const useGlobalConfig = defineStore({ this.initialize_config(); this.initialize_state(); }, + resetTmpTranslation() { + this.tmpMachineTranslate = {}; + }, setStudents(students: Student[]) { this.students = students; },