瀏覽代碼

:art: 托盘菜单支持多语言 https://github.com/siyuan-note/siyuan/issues/6883

Liang Ding 2 年之前
父節點
當前提交
a8201b8474

+ 10 - 0
app/appearance/langs/en_US.json

@@ -846,6 +846,16 @@
     "xy": "%d years %s",
     "max": "a long while %s"
   },
+  "_trayMenu": {
+    "showWindow": "Show Window",
+    "hideWindow": "Hide Window",
+    "setWindowTop": "Set Window top",
+    "cancelWindowTop": "Cancel Window top",
+    "officialWebsite": "Visit official website",
+    "openSource": "Visit Project on Github",
+    "resetWindow": "Reset Window on restart",
+    "quit": "Quit application"
+  },
   "_kernel": {
     "0": "Query notebook failed",
     "1": "Duplicated filename",

+ 10 - 1
app/appearance/langs/es_ES.json

@@ -680,7 +680,6 @@
   "export3": "Sólo texto de anclaje",
   "export4": "Notas a pie de página",
   "export5": "Ref. de anotación en PDF",
-  "export6": "Fusionar subdocumentos",
   "export6": "Sobre el manejo del texto ancla en las anotaciones PDF al exportar",
   "export7": "Nombre de archivo - Número de página - Texto ancla",
   "export8": "Sólo texto ancla",
@@ -847,6 +846,16 @@
     "xy": "%d años %s",
     "max": "mucho tiempo %s"
   },
+  "_trayMenu": {
+    "showWindow": "Mostrar ventana",
+    "hideWindow": "Ocultar ventana",
+    "setWindowTop": "Establecer parte superior de la ventana",
+    "cancelWindowTop": "Cancelar ventana superior",
+    "officialWebsite": "Visita el sitio web oficial",
+    "openSource": "Visita el proyecto en Github",
+    "resetWindow": "Restablecer ventana al reiniciar",
+    "quit": "Salir de la aplicación"
+  },
   "_kernel": {
     "0": "Consulta al cuaderno de notas fallido",
     "1": "Nombre de archivo duplicado",

+ 10 - 0
app/appearance/langs/fr_FR.json

@@ -846,6 +846,16 @@
     "xy": "%d ans %s",
     "max": "un bon moment %s"
   },
+  "_trayMenu": {
+    "showWindow": "Afficher la fenêtre principale",
+    "hideWindow": "Masquer la fenêtre principale",
+    "setWindowTop": "Fenêtre en haut",
+    "cancelWindowTop": "Annuler le haut de la fenêtre",
+    "officialWebsite": "Visiter le site officiel",
+    "openSource": "Accéder aux projets open source GitHub",
+    "resetWindow": "Réinitialiser l'état de la fenêtre au redémarrage",
+    "quit": "Quitter le programme"
+  },
   "_kernel": {
     "0": "Échec du cahier de requêtes",
     "1": "Nom de fichier dupliqué",

+ 10 - 0
app/appearance/langs/zh_CHT.json

@@ -846,6 +846,16 @@
     "xy": "%d 年%s",
     "max": "很久%s"
   },
+  "_trayMenu": {
+    "showWindow": "顯示主窗口",
+    "hideWindow": "隱藏主窗口",
+    "setWindowTop": "窗口置頂",
+    "cancelWindowTop": "取消窗口置頂",
+    "officialWebsite": "訪問官方網站",
+    "openSource": "訪問 GitHub 開源項目",
+    "resetWindow": "重啟時重置窗口",
+    "quit": "退出程序"
+  },
   "_kernel": {
     "0": "查詢筆記本失敗",
     "1": "檔案名重複",

+ 10 - 0
app/appearance/langs/zh_CN.json

@@ -846,6 +846,16 @@
     "xy": "%d 年%s",
     "max": "很久%s"
   },
+  "_trayMenu": {
+    "showWindow": "显示主窗口",
+    "hideWindow": "隐藏主窗口",
+    "setWindowTop": "窗口置顶",
+    "cancelWindowTop": "取消窗口置顶",
+    "officialWebsite": "访问官方网站",
+    "openSource": "访问 GitHub 开源项目",
+    "resetWindow": "重启时重置窗口",
+    "quit": "退出程序"
+  },
   "_kernel": {
     "0": "查询笔记本失败",
     "1": "文件名重复",

+ 60 - 38
app/electron/main.js

@@ -393,48 +393,66 @@ const boot = () => {
     globalShortcut.unregisterAll()
     writeLog('exited ui')
   })
-  ipcMain.on('siyuan-init', async () => {
+
+  let trayMenu = {
+    "showWindow": "Show Window",
+    "hideWindow": "Hide Window",
+    "setWindowTop": "Set Window top",
+    "cancelWindowTop": "Cancel Window top",
+    "officialWebsite": "Visit official website",
+    "openSource": "Visit Project on Github",
+    "resetWindow": "Reset Window on restart",
+    "quit": "Quit application"
+  }
+  ipcMain.on('siyuan-init', async (event, languages) => {
+    trayMenu = languages['_trayMenu'];
+    resetTrayMenu()
     await fetch(getServer() + '/api/system/uiproc?pid=' + process.pid,
       {method: 'POST'})
   })
 
-  // 系统托盘菜单
-  const trayMenuTemplate = [
-    {
-      label: 'Official Website',
-      click: () => {
-        shell.openExternal('https://b3log.org/siyuan/')
-      },
-    },
-    {
-      label: 'Open Source',
-      click: () => {
-        shell.openExternal('https://github.com/siyuan-note/siyuan')
-      },
-    },
-    {
-      label: '中文反馈',
-      click: () => {
-        shell.openExternal('https://ld246.com/article/1649901726096')
+  const resetTrayMenu = () => {
+    if ('win32' !== process.platform && 'linux' !== process.platform) {
+      return
+    }
+
+    const trayMenuTemplate = buildTrayMenuTemplate()
+    const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
+    tray.setContextMenu(contextMenu)
+  }
+
+  const buildTrayMenuTemplate = () => {
+    return [
+      {
+        label: trayMenu.officialWebsite,
+        click: () => {
+          shell.openExternal('https://b3log.org/siyuan/')
+        },
       },
-    },
-    {
-      label: 'Reset Window on restart',
-      type: 'checkbox',
-      click: v => {
-        resetWindowStateOnRestart = v.checked
+      {
+        label: trayMenu.openSource,
+        click: () => {
+          shell.openExternal('https://github.com/siyuan-note/siyuan')
+        },
       },
-    },
-    {
-      label: 'Quit',
-      click: () => {
-        mainWindow.webContents.send('siyuan-save-close', true)
+      {
+        label: trayMenu.resetWindow,
+        type: 'checkbox',
+        click: v => {
+          resetWindowStateOnRestart = v.checked
+        },
       },
-    }
-  ]
+      {
+        label: trayMenu.quit,
+        click: () => {
+          mainWindow.webContents.send('siyuan-save-close', true)
+        },
+      }
+    ]
+  }
 
   const showWndMenu = {
-    label: 'Hide Window',
+    label: trayMenu.hideWindow,
     click: () => {
       showHideWnd()
     },
@@ -447,7 +465,8 @@ const boot = () => {
       mainWindow.show()
 
       if ('win32' === process.platform || 'linux' === process.platform) {
-        showWndMenu.label = "Hide Window"
+        showWndMenu.label = trayMenu.hideWindow
+        const trayMenuTemplate = buildTrayMenuTemplate()
         trayMenuTemplate.splice(0, 1, showWndMenu)
         const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
         tray.setContextMenu(contextMenu)
@@ -456,7 +475,8 @@ const boot = () => {
       mainWindow.hide()
 
       if ('win32' === process.platform || 'linux' === process.platform) {
-        showWndMenu.label = "Show Window"
+        showWndMenu.label = trayMenu.showWindow
+        const trayMenuTemplate = buildTrayMenuTemplate()
         trayMenuTemplate.splice(0, 1, showWndMenu)
         const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
         tray.setContextMenu(contextMenu)
@@ -480,6 +500,7 @@ const boot = () => {
     tray = new Tray(path.join(appDir, 'stage', 'icon-large.png'))
     tray.setToolTip('SiYuan v' + appVer)
 
+    const trayMenuTemplate = buildTrayMenuTemplate()
     // 插入显示/隐藏窗口菜单
     trayMenuTemplate.splice(0, 0, showWndMenu)
 
@@ -487,17 +508,17 @@ const boot = () => {
     if ('win32' === process.platform) {
       // Windows 端支持窗口置顶 https://github.com/siyuan-note/siyuan/issues/6860
       changeWndTop = {
-        label: 'Set Window top',
+        label: trayMenu.setWindowTop,
         click: () => {
           if (!mainWindow.isAlwaysOnTop()) {
             mainWindow.setAlwaysOnTop(true)
-            changeWndTop.label = 'Cancel Window top'
+            changeWndTop.label = trayMenu.cancelWindowTop
             trayMenuTemplate.splice(1, 1, changeWndTop)
             const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
             tray.setContextMenu(contextMenu)
           } else {
             mainWindow.setAlwaysOnTop(false)
-            changeWndTop.label = 'Set Window top'
+            changeWndTop.label = trayMenu.setWindowTop
             trayMenuTemplate.splice(1, 1, changeWndTop)
             const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
             tray.setContextMenu(contextMenu)
@@ -823,6 +844,7 @@ app.on('before-quit', (event) => {
 })
 
 const {powerMonitor} = require('electron')
+const {build} = require("electron-builder");
 
 powerMonitor.on('suspend', () => {
   writeLog('system suspend')

+ 1 - 1
app/src/util/onGetConfig.ts

@@ -131,7 +131,7 @@ export const onGetConfig = (isStart: boolean) => {
     }
     /// #if !BROWSER
     ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSE, window.siyuan.config.appearance.closeButtonBehavior);
-    ipcRenderer.send(Constants.SIYUAN_INIT);
+    ipcRenderer.send(Constants.SIYUAN_INIT, window.siyuan.languages);
     ipcRenderer.send(Constants.SIYUAN_HOTKEY, hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom));
     /// #endif
     if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {