Skip to content

Commit

Permalink
新增使用特定的翻译引擎翻译文本快捷键
Browse files Browse the repository at this point in the history
  • Loading branch information
u3u committed Sep 23, 2017
1 parent b1f8e0c commit 06f65d6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/renderer/views/TransitionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ export default {
'meta+shift+1': this.changeSourceLanguage,
'meta+shift+2': this.changeTargetLanguage,
'meta+1': () => this.speakLanguage('source'),
'meta+2': () => this.speakLanguage('target')
'meta+2': () => this.speakLanguage('target'),
'meta+ctrl+1': () => this.translation('BaiDu'),
'meta+ctrl+2': () => this.translation('YouDao'),
'meta+ctrl+3': () => this.translation('Google'),
'meta+ctrl+4': () => this.translation('GoogleCN'),
'meta+q': () => remote.app.quit()
}
}
},
Expand Down Expand Up @@ -172,6 +177,11 @@ export default {
menu.append(new MenuItem({ label: '说源语言', accelerator: 'Cmd+1', enabled: !!this.model.source.value && this.model.source.country !== 'auto', click: () => this.speakLanguage('source') }))
menu.append(new MenuItem({ label: '说目标语言', accelerator: 'Cmd+2', enabled: !!this.model.target.value, click: () => this.speakLanguage('target') }))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: '使用百度翻译', accelerator: 'Ctrl+Cmd+1', enabled: !!this.model.source.value, click: () => this.translation('BaiDu') }))
menu.append(new MenuItem({ label: '使用有道翻译', accelerator: 'Ctrl+Cmd+2', enabled: !!this.model.source.value, click: () => this.translation('YouDao') }))
menu.append(new MenuItem({ label: '使用谷歌翻译', accelerator: 'Ctrl+Cmd+3', enabled: !!this.model.source.value, click: () => this.translation('Google') }))
menu.append(new MenuItem({ label: '使用谷歌(国内)', accelerator: 'Ctrl+Cmd+4', enabled: !!this.model.source.value, click: () => this.translation('GoogleCN') }))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: '退出 Google 翻译', accelerator: 'Cmd+Q', click: remote.app.quit }))
menu.popup(Window)
},
Expand Down Expand Up @@ -249,14 +259,14 @@ export default {
this.model[action].progress.type = ''
this.audio.pause()
},
async translation () {
async translation (engine) {
if (!this.model.source.value) return
this.model.target.value = ''
this.view.loading = true
await Thread.sleep(200) // 至少延迟 200ms 否则会导致窗口抖动
try {
const json = await tjs.translate({
api: this.engine,
api: typeof engine === 'string' ? engine : this.engine,
text: this.model.source.value,
from: this.model.source.country,
to: this.model.target.country
Expand Down

0 comments on commit 06f65d6

Please sign in to comment.