-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*! | ||
* AriaNg GUI | ||
* | ||
* Copyright (c) 2018 Xmader | ||
* Released under the MIT license | ||
* | ||
* Source Code: https://github.com/Xmader/aria-ng-gui | ||
* | ||
*/ | ||
|
||
const process = require("process") | ||
const { Menu } = require("electron") | ||
const Translate = require("./translate.js") | ||
|
||
const isDev = process.argv.pop() == "dev" | ||
|
||
|
||
// 增加右键菜单 | ||
const contextMenuTemplate = [ | ||
{ label: "撤销", role: "undo", accelerator: "CmdOrCtrl+Z" }, | ||
{ label: "恢复", role: "redo", accelerator: "CmdOrCtrl+Y" }, | ||
{ type: "separator" }, //分隔线 | ||
{ label: "剪切", role: "cut", accelerator: "CmdOrCtrl+X" }, //Cut菜单项 | ||
{ label: "复制", role: "copy", accelerator: "CmdOrCtrl+C" }, //Copy菜单项 | ||
{ label: "粘贴", role: "paste", accelerator: "CmdOrCtrl+V" }, //Paste菜单项 | ||
{ type: "separator" }, //分隔线 | ||
{ label: "全选", role: "selectall", accelerator: "CmdOrCtrl+A" }, //Select All菜单项 | ||
]; | ||
if (isDev) { | ||
[ | ||
{ type: "separator" }, //分隔线 | ||
{ label: "重新加载页面", role: "reload" }, | ||
{ label: "切换开发者工具", role: "toggledevtools" }, | ||
].forEach(x => contextMenuTemplate.push(x)) | ||
} | ||
|
||
const appMenuTemplate = [ | ||
{ | ||
submenu: [{ label: "退出", role: "quit" }] | ||
}, | ||
{ | ||
label: "编辑", | ||
submenu: contextMenuTemplate | ||
} | ||
] | ||
|
||
|
||
const buildMenu = (locale) => { | ||
|
||
const _buildMenuFromTemplate = (menuTemplate) => { | ||
if (locale != "zh-CN") { | ||
menuTemplate = Translate(menuTemplate, locale) | ||
} | ||
return Menu.buildFromTemplate(menuTemplate) | ||
} | ||
|
||
const contextMenu = _buildMenuFromTemplate(contextMenuTemplate) | ||
const appMenu = _buildMenuFromTemplate(appMenuTemplate) | ||
|
||
return { | ||
contextMenu, | ||
appMenu | ||
} | ||
} | ||
|
||
module.exports = { | ||
buildMenu | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* AriaNg GUI | ||
* | ||
* Copyright (c) 2018 Xmader | ||
* Released under the MIT license | ||
* | ||
* Source Code: https://github.com/Xmader/aria-ng-gui | ||
* | ||
* translate.js - 翻译菜单项 | ||
* | ||
*/ | ||
|
||
const translations = { | ||
"撤销": "Undo", | ||
"恢复": "Redo", | ||
"剪切": "Cut", | ||
"复制": "Copy", | ||
"粘贴": "Paste", | ||
"全选": "Select All", | ||
"重新加载页面": "Reload", | ||
"切换开发者工具": "Toggle Developer Tools", | ||
"退出": "Quit", | ||
"编辑": "Edit", | ||
} | ||
|
||
const Translate = (menuTemplate, locale = "en-US") => { | ||
const _translateLabels = (x) => { | ||
if (x.label) { | ||
x.label = translations[x.label] | ||
} | ||
if (x.submenu) { | ||
x.submenu = x.submenu.map(_translateLabels) | ||
} | ||
return x | ||
} | ||
|
||
return menuTemplate.map(_translateLabels) | ||
} | ||
|
||
module.exports = Translate |