Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): don't expose the plus key as a translatable shortcut label
Elian Doran263e3726eb4d
diff --git a/apps/client/src/services/keyboard_shortcut_display.spec.ts b/apps/client/src/services/keyboard_shortcut_display.spec.tsindex 89c58eb6d2..44153e11cb 100644--- a/apps/client/src/services/keyboard_shortcut_display.spec.ts+++ b/apps/client/src/services/keyboard_shortcut_display.spec.ts@@ -66,9 +66,11 @@ describe("keyboard_shortcut_display", () => {expect(formatShortcutKey("PageDown")).toBe("Page Down");});- it("renders the plus key (named token or glyph) as '+'", () => {+ it("renders the plus key (named token or glyph) as '+' and never translates it", () => {expect(formatShortcutKey("Plus")).toBe("+");expect(formatShortcutKey("+")).toBe("+");+ // Normalization-only token: a translator must not be able to override the universal glyph.+ expect(formatShortcutKey("Plus", fakeTranslate)).toBe("+");});it("passes non-table tokens through verbatim (letters, digits, function keys, punctuation)", () => {diff --git a/apps/client/src/services/keyboard_shortcut_display.ts b/apps/client/src/services/keyboard_shortcut_display.tsindex 656a5eb7f2..3b90216efd 100644--- a/apps/client/src/services/keyboard_shortcut_display.ts+++ b/apps/client/src/services/keyboard_shortcut_display.ts@@ -88,11 +88,17 @@ export function splitShortcutForDisplay(shortcut: string): string[] {* function key, or punctuation key — is returned unchanged.*/export function formatShortcutKey(token: string, translate?: ShortcutKeyTranslator): string {- const entry = TRANSLATABLE_KEYS[token.toLowerCase()];+ const entry = KEY_LABELS[token.toLowerCase()];if (!entry) {return token;}+ // Entries without an `id` are display normalization only (a universal glyph such as "+"), not+ // translation — they never consult the translator and are never exposed as translation keys.+ if (!entry.id) {+ return entry.en;+ }+const translated = translate?.(entry.id);return translated ? translated : entry.en;}@@ -102,12 +108,13 @@ function stripGlobalPrefix(shortcut: string): string {}/**- * Maps a raw shortcut token (lowercased, aliases collapsed) to its stable translation `id` and the- * built-in English label used when no translation is available. Tokens absent from this table are- * rendered verbatim, so only modifiers and named keys — the parts that differ across languages — need- * an entry.+ * Maps a raw shortcut token (lowercased, aliases collapsed) to its display label. An entry with an+ * `id` is *translatable* — the `id` resolves a per-language label, with `en` as the fallback. An entry+ * without an `id` is *normalization only*: a universal glyph (e.g. the stored word "Plus" shown as+ * "+") that reads identically in every language and must not be offered to translators. Tokens absent+ * from this table — letters, digits, function keys, punctuation — are rendered verbatim.*/-const TRANSLATABLE_KEYS: Record<string, { id: string; en: string }> = {+const KEY_LABELS: Record<string, { id?: string; en: string }> = {// Modifiers.ctrl: { id: "ctrl", en: "Ctrl" },control: { id: "ctrl", en: "Ctrl" },@@ -141,9 +148,10 @@ const TRANSLATABLE_KEYS: Record<string, { id: string; en: string }> = {arrowleft: { id: "left", en: "Left" },right: { id: "right", en: "Right" },arrowright: { id: "right", en: "Right" },- // The plus key is stored as the named token `Plus`; displayed as the "+" glyph.- plus: { id: "plus", en: "+" },- "+": { id: "plus", en: "+" },+ // The plus key is stored as the named token `Plus`; normalized to the universal "+" glyph. No+ // `id`: "+" is language-neutral, so it is never routed through translation.+ plus: { en: "+" },+ "+": { en: "+" },insert: { id: "insert", en: "Insert" },ins: { id: "insert", en: "Insert" }};diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex d2941cbc78..b48287962c 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1954,7 +1954,6 @@"down": "Down","left": "Left","right": "Right",- "plus": "+","insert": "Insert"},"spellcheck": {