summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/command.tsx
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-03-13 06:48:38 -0500
committerGitHub <[email protected]>2026-03-13 06:48:38 -0500
commit05cb3c87ca387be41aceb5ccad978c6848a56f70 (patch)
tree2b592d2aa90d0fdb7ea72aa392507e2277b92ba5 /packages/app/src/context/command.tsx
parent270cb0b8b4265ac0965ac8b94a58a3bca86fa558 (diff)
downloadopencode-05cb3c87ca387be41aceb5ccad978c6848a56f70.tar.gz
opencode-05cb3c87ca387be41aceb5ccad978c6848a56f70.zip
chore(app): i18n sync (#17283)
Diffstat (limited to 'packages/app/src/context/command.tsx')
-rw-r--r--packages/app/src/context/command.tsx61
1 files changed, 51 insertions, 10 deletions
diff --git a/packages/app/src/context/command.tsx b/packages/app/src/context/command.tsx
index 03bd6318d..2c6799d12 100644
--- a/packages/app/src/context/command.tsx
+++ b/packages/app/src/context/command.tsx
@@ -2,6 +2,7 @@ import { createEffect, createMemo, onCleanup, onMount, type Accessor } from "sol
import { createStore } from "solid-js/store"
import { createSimpleContext } from "@opencode-ai/ui/context"
import { useDialog } from "@opencode-ai/ui/context/dialog"
+import { dict as en } from "@/i18n/en"
import { useLanguage } from "@/context/language"
import { useSettings } from "@/context/settings"
import { Persist, persisted } from "@/utils/persist"
@@ -13,6 +14,27 @@ const DEFAULT_PALETTE_KEYBIND = "mod+shift+p"
const SUGGESTED_PREFIX = "suggested."
const EDITABLE_KEYBIND_IDS = new Set(["terminal.toggle", "terminal.new", "file.attach"])
+type KeyLabel =
+ | "common.key.ctrl"
+ | "common.key.alt"
+ | "common.key.shift"
+ | "common.key.meta"
+ | "common.key.space"
+ | "common.key.backspace"
+ | "common.key.enter"
+ | "common.key.tab"
+ | "common.key.delete"
+ | "common.key.home"
+ | "common.key.end"
+ | "common.key.pageUp"
+ | "common.key.pageDown"
+ | "common.key.insert"
+ | "common.key.esc"
+
+function keyText(key: KeyLabel, t?: (key: KeyLabel) => string) {
+ return t ? t(key) : en[key]
+}
+
function actionId(id: string) {
if (!id.startsWith(SUGGESTED_PREFIX)) return id
return id.slice(SUGGESTED_PREFIX.length)
@@ -145,7 +167,7 @@ export function matchKeybind(keybinds: Keybind[], event: KeyboardEvent): boolean
return false
}
-export function formatKeybind(config: string): string {
+export function formatKeybind(config: string, t?: (key: KeyLabel) => string): string {
if (!config || config === "none") return ""
const keybinds = parseKeybind(config)
@@ -154,10 +176,10 @@ export function formatKeybind(config: string): string {
const kb = keybinds[0]
const parts: string[] = []
- if (kb.ctrl) parts.push(IS_MAC ? "⌃" : "Ctrl")
- if (kb.alt) parts.push(IS_MAC ? "⌥" : "Alt")
- if (kb.shift) parts.push(IS_MAC ? "⇧" : "Shift")
- if (kb.meta) parts.push(IS_MAC ? "⌘" : "Meta")
+ if (kb.ctrl) parts.push(IS_MAC ? "⌃" : keyText("common.key.ctrl", t))
+ if (kb.alt) parts.push(IS_MAC ? "⌥" : keyText("common.key.alt", t))
+ if (kb.shift) parts.push(IS_MAC ? "⇧" : keyText("common.key.shift", t))
+ if (kb.meta) parts.push(IS_MAC ? "⌘" : keyText("common.key.meta", t))
if (kb.key) {
const keys: Record<string, string> = {
@@ -167,10 +189,29 @@ export function formatKeybind(config: string): string {
arrowright: "→",
comma: ",",
plus: "+",
- space: "Space",
+ }
+ const named: Record<string, KeyLabel> = {
+ backspace: "common.key.backspace",
+ delete: "common.key.delete",
+ end: "common.key.end",
+ enter: "common.key.enter",
+ esc: "common.key.esc",
+ escape: "common.key.esc",
+ home: "common.key.home",
+ insert: "common.key.insert",
+ pagedown: "common.key.pageDown",
+ pageup: "common.key.pageUp",
+ space: "common.key.space",
+ tab: "common.key.tab",
}
const key = kb.key.toLowerCase()
- const displayKey = keys[key] ?? (key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1))
+ const displayKey =
+ keys[key] ??
+ (named[key]
+ ? keyText(named[key], t)
+ : key.length === 1
+ ? key.toUpperCase()
+ : key.charAt(0).toUpperCase() + key.slice(1))
parts.push(displayKey)
}
@@ -364,17 +405,17 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
},
keybind(id: string) {
if (id === PALETTE_ID) {
- return formatKeybind(settings.keybinds.get(PALETTE_ID) ?? DEFAULT_PALETTE_KEYBIND)
+ return formatKeybind(settings.keybinds.get(PALETTE_ID) ?? DEFAULT_PALETTE_KEYBIND, language.t)
}
const base = actionId(id)
const option = options().find((x) => actionId(x.id) === base)
- if (option?.keybind) return formatKeybind(option.keybind)
+ if (option?.keybind) return formatKeybind(option.keybind, language.t)
const meta = catalog[base]
const config = bind(base, meta?.keybind)
if (!config) return ""
- return formatKeybind(config)
+ return formatKeybind(config, language.t)
},
show: showPalette,
keybinds(enabled: boolean) {