From 1565a0fd808d8b901989e491fad9ccd4aee04442 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 27 Jul 2025 21:47:30 +0300 Subject: [PATCH] feat(command_palette): differentiate tree-based operations --- apps/client/src/services/command_registry.ts | 9 ++++++++- apps/client/src/services/i18n.ts | 7 +++++++ apps/client/src/translations/en/translation.json | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/client/src/services/command_registry.ts b/apps/client/src/services/command_registry.ts index 965f7eaac..3d73501e4 100644 --- a/apps/client/src/services/command_registry.ts +++ b/apps/client/src/services/command_registry.ts @@ -1,5 +1,6 @@ import appContext, { type CommandNames } from "../components/app_context.js"; import type NoteTreeWidget from "../widgets/note_tree.js"; +import { t, translationsInitializedPromise } from "./i18n.js"; import keyboardActions, { Action } from "./keyboard_actions.js"; export interface CommandDefinition { @@ -150,6 +151,7 @@ class CommandRegistry { private async loadKeyboardActionsAsync() { try { + await translationsInitializedPromise; const actions = await keyboardActions.getActions(); this.registerKeyboardActions(actions); } catch (error) { @@ -172,10 +174,15 @@ class CommandRegistry { // Get the primary shortcut (first one in the list) const primaryShortcut = action.effectiveShortcuts?.[0]; + let name = action.friendlyName; + if (action.scope === "note-tree") { + name = t("command_palette.tree-action-name", { name: action.friendlyName }); + } + // Create a command definition from the keyboard action const commandDef: CommandDefinition = { id: action.actionName, - name: action.friendlyName, + name, description: action.description, icon: action.iconClass, shortcut: primaryShortcut ? this.formatShortcut(primaryShortcut) : undefined, diff --git a/apps/client/src/services/i18n.ts b/apps/client/src/services/i18n.ts index 25c98fe39..a85df588c 100644 --- a/apps/client/src/services/i18n.ts +++ b/apps/client/src/services/i18n.ts @@ -6,6 +6,11 @@ import type { Locale } from "@triliumnext/commons"; let locales: Locale[] | null; +/** + * A deferred promise that resolves when translations are initialized. + */ +export let translationsInitializedPromise = jQuery.Deferred(); + export async function initLocale() { const locale = (options.get("locale") as string) || "en"; @@ -19,6 +24,8 @@ export async function initLocale() { }, returnEmptyString: false }); + + translationsInitializedPromise.resolve(); } export function getAvailableLocales() { diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 7fd0bc700..651291b20 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1987,5 +1987,8 @@ "delete-column-confirmation": "Are you sure you want to delete this column? The corresponding attribute will be deleted in the notes under this column as well.", "new-item": "New item", "add-column": "Add Column" + }, + "command_palette": { + "tree-action-name": "Tree: {{name}}" } }