Browse Source

Add `ICommand.langText` for plugin (#8589)

* :art: Support custom text when plugin register command

REF: https://github.com/siyuan-note/petal/pull/9

* :art: Support custom text when plugin register command
Yingyi / 颖逸 2 years ago
parent
commit
1a7edf3b3c
2 changed files with 3 additions and 2 deletions
  1. 1 1
      app/src/config/keymap.ts
  2. 2 1
      app/src/types/index.d.ts

+ 1 - 1
app/src/config/keymap.ts

@@ -39,7 +39,7 @@ export const keymap = {
             item.commands.forEach(command => {
             item.commands.forEach(command => {
                 const keyValue = updateHotkeyTip(command.customHotkey);
                 const keyValue = updateHotkeyTip(command.customHotkey);
                 commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action">
                 commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action">
-    <span class="b3-list-item__text">${item.i18n[command.langKey]}</span>
+    <span class="b3-list-item__text">${command.langText || item.i18n[command.langKey] || command.langKey}</span>
     <span data-type="reset" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.reset}">
     <span data-type="reset" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.reset}">
         <svg><use xlink:href="#iconUndo"></use></svg>
         <svg><use xlink:href="#iconUndo"></use></svg>
     </span>
     </span>

+ 2 - 1
app/src/types/index.d.ts

@@ -326,7 +326,8 @@ interface IDockTab {
 }
 }
 
 
 interface ICommand {
 interface ICommand {
-    langKey: string, // 多语言 key
+    langKey: string, // 用于区分不同快捷键的 key, 同时作为 i18n 的字段名
+    langText?: string, // 显示的文本, 指定后不再使用 langKey 对应的 i18n 文本
     hotkey: string,
     hotkey: string,
     customHotkey?: string,
     customHotkey?: string,
     callback?: () => void
     callback?: () => void