Skip to content

Commit

Permalink
feat(toolbox): 智能切换校对模式
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9804 committed Feb 5, 2025
1 parent 146ef8c commit bdb5ddd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ const mmtkGroup = computed(() =>
:idx="idx"
:total="total"
/>
<div flex flex-col gap-4 mb-5 pt-4 px-4 class="bg-[#f2f2f2] @dark:bg-slate-900">
<div
flex
flex-col
gap-4
mb-5
pt-4
px-4
class="bg-[#f2f2f2] @dark:bg-slate-900"
>
<MmtkUnit v-for="msg in mmtkGroup" :key="msg.Id" :msg="msg" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isMac } from "../../public/helper/isMac";
import { saveAs } from "file-saver";
import { dump } from "js-yaml";
import { useRouter } from "vue-router";
import "@arco-design/web-vue/es/button/style/css.js"
import "@arco-design/web-vue/es/button/style/css.js";
const router = useRouter();
const useMomotalkEditorStore = momotalkEditorStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</template>
<script setup lang="ts">
import jsYaml from "js-yaml";
import { ref, computed } from "vue";
import { ref } from "vue";
import { Scenario } from "../../ScenarioEditor/types/content";
import type { FileContent } from "../types/Momotalks";
import { momotalkEditorStore } from "../store/momotalkEditorStore";
Expand Down Expand Up @@ -138,6 +138,10 @@ function handleFile(file: File) {
tempMomotalkData.value = result.content as FileContent;
if (checkMomotalkFileValidity(tempMomotalkData.value)) {
useMomotalkEditorStore.setMomotalkFileData(tempMomotalkData.value);
useMomotalkEditorStore.setFilename(file.name);
if (inferProofread()) {
useMomotalkEditorStore.setProofreaderMode(true);
}
} else {
Message.error("文件不是有效的 MomoTalk 数据文件");
}
Expand Down Expand Up @@ -178,20 +182,36 @@ function filePreProcessor(file: File): Promise<{
}
}
function inferProofread(content: any, fileName: string): boolean {
function inferProofread(): boolean {
const fileName = useMomotalkEditorStore.getFilename ?? "";
const content = useMomotalkEditorStore.getMomotalkFileData ?? {};
// 根据内容,推断是否进入校对模式
// 去除后缀后的文件名包含"未校对",返回 true
// Unit 中某一条目的 unsure flag 为 true,返回 true
// Unit 中 TextCn 有内容的条目占比超过 95%,返回 true
// 去除后缀的文件名包含"已翻",返回 true
// title / content 中某一条目的 unsure flag 为 true,返回 true
// title / content 中 TextCn / MessageCN 有内容的条目占比超过 90%,返回 true
// 否则返回 false
const fileNameWithoutSuffix = fileName.replace(/\.[^/.]+$/, "");
if (fileNameWithoutSuffix.includes("未校对")) {
if (fileNameWithoutSuffix.includes("已翻")) {
return true;
}
const scenarioUnits = content.content;
const unsureCount = scenarioUnits.filter((unit: any) => unit.Unsure).length;
const textCnCount = scenarioUnits.filter((unit: any) => unit.TextCn).length;
if (unsureCount > 0 || textCnCount / scenarioUnits.length > 0.95) {
// @ts-expect-error
if (!content || !content.title || !content.content) {
return false;
}
// @ts-ignore
const titleUnits = content.title;
// @ts-ignore
const messageUnits = content.content;
const merged = [...titleUnits, ...messageUnits];
const unsureCount = merged.filter((unit: any) => unit.unsure).length;
if (unsureCount > 0) {
return true;
}
const textCnCount = titleUnits.filter(unit => unit.TextCn).length;
const messageCnCount = messageUnits.filter(unit => unit.MessageCN || !unit.ImagePath).length;
if (textCnCount + messageCnCount > merged.length * 0.9) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { defineStore } from "pinia";
import type {
FileContent,
Language,
Title,
Content,
ContentTranslation,
} from "../types/Momotalks";
import type { FileContent, Language, Title, Content } from "../types/Momotalks";

// composition API 会导致 persistedstate 不能持久化存储
export const momotalkEditorStore = defineStore("momotalk-editor", {
state: () => ({
momotalkFileData: null as FileContent | null,
filename: "",
defaultTranslator: "",
defaultProofreader: "",
selectedTranslation: "Jp" as Language,
Expand All @@ -21,6 +16,7 @@ export const momotalkEditorStore = defineStore("momotalk-editor", {

getters: {
getMomotalkFileData: state => state.momotalkFileData,
getFilename: state => state.filename,
getTranslator: state =>
state.momotalkFileData?.translator || state.defaultTranslator,
getProofreader: state =>
Expand Down Expand Up @@ -68,6 +64,9 @@ export const momotalkEditorStore = defineStore("momotalk-editor", {
setMomotalkFileData(data: FileContent) {
this.momotalkFileData = data;
},
setFilename(filename: string) {
this.filename = filename;
},
setTranslator(translator: string) {
this.defaultTranslator = translator;
this.momotalkFileData!.translator = translator;
Expand Down Expand Up @@ -96,6 +95,8 @@ export const momotalkEditorStore = defineStore("momotalk-editor", {
},
reset() {
this.momotalkFileData = null;
this.filename = "";
this.isProofreaderMode = false;
},
setIsDownloaded(isDownloaded: boolean) {
this.isDownloaded = isDownloaded;
Expand All @@ -105,6 +106,7 @@ export const momotalkEditorStore = defineStore("momotalk-editor", {
storage: localStorage,
pick: [
"momotalkFileData",
"filename",
"defaultTranslator",
"defaultProofreader",
"selectedTranslation",
Expand Down

0 comments on commit bdb5ddd

Please sign in to comment.