Make some parts of shortcuts in dialog translatable (#24955)

* Make some parts of shortcuts in dialog translatable

* Adjust translations
This commit is contained in:
Jan-Philipp Benecke 2025-04-08 07:43:54 +02:00 committed by GitHub
parent d1465a79ae
commit f0f60bae78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 7 deletions

View File

@ -14,9 +14,11 @@ interface Text {
key: LocalizeKeys; key: LocalizeKeys;
} }
type ShortcutString = string | { key: LocalizeKeys };
interface Shortcut { interface Shortcut {
type: "shortcut"; type: "shortcut";
shortcut: string[]; shortcut: ShortcutString[];
key: LocalizeKeys; key: LocalizeKeys;
} }
@ -51,7 +53,7 @@ const _SHORTCUTS: Section[] = [
}, },
{ {
type: "shortcut", type: "shortcut",
shortcut: ["CRTL/CMND", "F"], shortcut: [{ key: "ui.dialogs.shortcuts.shortcuts.ctrl_cmd" }, "F"],
key: "ui.dialogs.shortcuts.searching.search_in_table", key: "ui.dialogs.shortcuts.searching.search_in_table",
}, },
], ],
@ -71,17 +73,23 @@ const _SHORTCUTS: Section[] = [
items: [ items: [
{ {
type: "shortcut", type: "shortcut",
shortcut: ["CRTL/CMND", "DRAG"], shortcut: [
{ key: "ui.dialogs.shortcuts.shortcuts.ctrl_cmd" },
{ key: "ui.dialogs.shortcuts.shortcuts.drag" },
],
key: "ui.dialogs.shortcuts.charts.drag_to_zoom", key: "ui.dialogs.shortcuts.charts.drag_to_zoom",
}, },
{ {
type: "shortcut", type: "shortcut",
shortcut: ["CRTL/CMND", "SCROLL WHEEL"], shortcut: [
{ key: "ui.dialogs.shortcuts.shortcuts.ctrl_cmd" },
{ key: "ui.dialogs.shortcuts.shortcuts.scroll_wheel" },
],
key: "ui.dialogs.shortcuts.charts.scroll_to_zoom", key: "ui.dialogs.shortcuts.charts.scroll_to_zoom",
}, },
{ {
type: "shortcut", type: "shortcut",
shortcut: ["DOUBLE CLICK"], shortcut: [{ key: "ui.dialogs.shortcuts.shortcuts.double_click" }],
key: "ui.dialogs.shortcuts.charts.double_click", key: "ui.dialogs.shortcuts.charts.double_click",
}, },
], ],
@ -113,10 +121,17 @@ class DialogShortcuts extends LitElement {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
private _renderShortcut(shortcut: string[], translationKey: LocalizeKeys) { private _renderShortcut(
shortcuts: ShortcutString[],
translationKey: LocalizeKeys
) {
const keys = shortcuts.map((shortcut) =>
typeof shortcut === "string" ? shortcut : this.hass.localize(shortcut.key)
);
return html` return html`
<div class="shortcut"> <div class="shortcut">
${shortcut.map((key) => html` <span>${key}</span>`)} ${keys.map((key) => html` <span>${key.toUpperCase()}</span>`)}
${this.hass.localize(translationKey)} ${this.hass.localize(translationKey)}
</div> </div>
`; `;

View File

@ -1895,6 +1895,12 @@
"title": "Shortcuts", "title": "Shortcuts",
"enable_shortcuts_hint": "For keyboard shortcuts to work, make sure you have them enabled in your {user_profile}.", "enable_shortcuts_hint": "For keyboard shortcuts to work, make sure you have them enabled in your {user_profile}.",
"enable_shortcuts_hint_user_profile": "user profile", "enable_shortcuts_hint_user_profile": "user profile",
"shortcuts": {
"double_click": "Double-click",
"scroll_wheel": "Scroll",
"drag": "Drag",
"ctrl_cmd": "Ctrl/Cmd"
},
"searching": { "searching": {
"title": "Searching", "title": "Searching",
"on_any_page": "On any page", "on_any_page": "On any page",