Skip to content

Commit

Permalink
autofill common character translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Icexbb committed Aug 11, 2023
1 parent b386af0 commit 333fadc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
20 changes: 19 additions & 1 deletion electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ app.whenReady().then(createWindow).then(initCore).then(function () {
? JSON.parse(fs.readFileSync(path.join(PROGRAM_DIR, 'setting.json')).toString())
: {};
setProxy(setting);
});
}).then(updateNameTranslation);
app.on('window-all-closed', function () {
AppRunning = false;
win = null;
Expand Down Expand Up @@ -601,3 +601,21 @@ ipcMain.on("task-new", function (_, args) {
}));
}
});
function updateNameTranslation() {
var url = "https://gist.githubusercontent.com/Icexbb/a973047364266e600dcc9db71417f431/raw/prsk_name_translation_jp_cn.json";
var filepath = path.join(PROGRAM_DIR, "prsk_name_translation_jp_cn.json");
return axios.get(url).then(function (resp) {
fs.writeFileSync(filepath, JSON.stringify(resp.data));
});
}
ipcMain.on("update-name-translation", function (event) {
event.returnValue = updateNameTranslation();
});
ipcMain.on("get-name-translation", function (event) {
var filepath = path.join(PROGRAM_DIR, "prsk_name_translation_jp_cn.json");
var data = {};
if (fs.existsSync(filepath))
data = JSON.parse(fs.readFileSync(filepath, "utf8"));
event.returnValue = data;
event.sender.send("name-translation", data);
});
23 changes: 21 additions & 2 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ app.whenReady().then(createWindow).then(initCore).then(() => {
? JSON.parse(fs.readFileSync(path.join(PROGRAM_DIR, 'setting.json')).toString())
: {}
setProxy(setting)
})
}).then(updateNameTranslation)

app.on('window-all-closed', () => {
AppRunning = false
Expand Down Expand Up @@ -346,7 +346,7 @@ ipcMain.on('select-file-exist-translated', function (event) {
dialog.showOpenDialog({
title: '选择已翻译文件',
properties: ['openFile'],
filters: [{name: '世界计划数据文件', extensions: [ 'txt', 'pjs.txt']}]
filters: [{name: '世界计划数据文件', extensions: ['txt', 'pjs.txt']}]
}).then(result => {
event.sender.send('selected-translated', result)
})
Expand Down Expand Up @@ -554,4 +554,23 @@ ipcMain.on("task-new", (_, args) => {
data: JSON.stringify({config: JSON.parse(args[0]), runAfterCreate: args[1]})
}))
}
})

function updateNameTranslation() {
let url = "https://gist.githubusercontent.com/Icexbb/a973047364266e600dcc9db71417f431/raw/prsk_name_translation_jp_cn.json"
let filepath = path.join(PROGRAM_DIR, "prsk_name_translation_jp_cn.json")
return axios.get(url).then(resp => {
fs.writeFileSync(filepath, JSON.stringify(resp.data))
})
}

ipcMain.on("update-name-translation", (event) => {
event.returnValue = updateNameTranslation()
})
ipcMain.on("get-name-translation", (event) => {
let filepath = path.join(PROGRAM_DIR, "prsk_name_translation_jp_cn.json")
let data: object = {}
if (fs.existsSync(filepath)) data = JSON.parse(fs.readFileSync(filepath, "utf8"))
event.returnValue = data
event.sender.send("name-translation", data)
})
68 changes: 48 additions & 20 deletions src/views/Translate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
</n-button>
</template>
</n-popover>
<n-popconfirm
positive-text="" negative-text=""
@positive-click="this.selectJson">
<n-popconfirm negative-text="" positive-text="" @positive-click="this.selectJson">
<template #trigger>
<n-button> 打开新文件</n-button>
</template>
<template #default>
<n-text>确认关闭? 未保存的更改将被舍弃!</n-text>
</template>
</n-popconfirm>
<n-popconfirm
positive-text="" negative-text=""
@positive-click="this.clearEventData">
<n-popconfirm negative-text="" positive-text="" @positive-click="this.clearEventData">
<template #trigger>
<n-button> 关闭文件</n-button>
</template>
Expand All @@ -42,8 +38,7 @@
<n-gi :span="2">
<n-statistic label="任务名称">
<n-input style="width: 80%;" v-model:value="this.taskName" placeholder=""
@update:value="this.dataChanged"
/>
@update:value="this.dataChanged"/>
</n-statistic>
</n-gi>
<n-gi :span="1">
Expand All @@ -67,14 +62,11 @@
</n-grid>
</template>
</n-page-header>
<n-space :item-style="{width:'90%'}" justify="center">
<template v-for="(data,index) in this.eventData.data " :key="index">
<TranslateCard
:translated="this.eventData.data.length==this.translated.data.length?
this.translated.data[index].ContentT:''"
@translation-changed="this.dataChanged" :data="data"
@character-translated="this.characterTranslated"
/>
<n-space :item-style="{ width: '90%' }" justify="center">
<template v-for="(data, index) in this.eventData.data " :key="index">
<TranslateCard :data="data" :translated="this.eventData.data.length == this.translated.data.length ?
this.translated.data[index].ContentT : ''"
@translation-changed="this.dataChanged" @character-translated="this.characterTranslated"/>
</template>
</n-space>
</n-space>
Expand Down Expand Up @@ -137,9 +129,13 @@ export default defineComponent({
const store = useTranslateTasksStore()
let eventData: StoryEventSet = store.eventData
eventData = this.autoFillCharaTranslation(eventData)
let taskName: string = store.taskName
let loadedFile: string = store.baseFile
let loaded: boolean = store.loaded
if (loaded) {
}
return {
bracketsOptions,
saveOptions,
Expand Down Expand Up @@ -249,7 +245,40 @@ export default defineComponent({
this.loaded = false
this.loadedFile = ""
this.eventData = new StoryEventSet([]) as StoryEventSet
}
},
autoFillCharaTranslation(eventData?: StoryEventSet) {
const chart = ipcRenderer.sendSync("get-name-translation")
if (eventData == undefined) {
if (this.loaded && this.eventData) {
for (let i = 0; i < this.eventData.data.length; i++) {
let chara: string = this.eventData.data[i].CharacterO
if (chart.hasOwnProperty(chara) && chart[chara].length != 0 && this.eventData.data[i].CharacterT.length == 0) {
this.eventData.data[i].CharacterT = chart[chara]
}
}
}
} else {
let e = eventData
for (let i = 0; i < e.data.length; i++) {
let chara: string = e.data[i].CharacterO
if (chart.hasOwnProperty(chara) && chart[chara].length != 0 && e.data[i].CharacterT.length == 0) {
e.data[i].CharacterT = chart[chara]
}
}
return e
}
},
updateCharaTranalation() {
ipcRenderer.sendSync("update-name-translation")
let chart = ipcRenderer.sendSync("get-name-translation")
for (let i = 0; i < this.eventData.data.length; i++) {
let chara: string = this.eventData.data[i].CharacterO
if (chart[chara] == undefined || chart[chara] == "" && this.eventData.data[i].CharacterT) {
chart[chara] = this.eventData.data[i].CharacterT
}
}
// TODO
},
},
watch: {
loadedFile: function () {
Expand All @@ -262,6 +291,7 @@ export default defineComponent({
this.taskName = path.basename(this.loadedFile, path.extname(this.loadedFile))
this.eventData = StoryEventSet.FromLegacy(GameStoryData.FromFile(this.loadedFile))
}
this.autoFillCharaTranslation()
} else {
this.clearEventData()
}
Expand All @@ -277,6 +307,4 @@ export default defineComponent({
})
</script>

<style scoped>
</style>
<style scoped></style>

0 comments on commit 333fadc

Please sign in to comment.