@@ -11,126 +11,138 @@ import type { HomeAssistant } from "../../types";
1111import { isMac } from "../../util/is_mac" ;
1212
1313interface Text {
14- type : "text" ;
15- key : LocalizeKeys ;
14+ textTranslationKey : LocalizeKeys ;
1615}
1716
18- type ShortcutString = string | { key : LocalizeKeys } ;
17+ interface LocalizedShortcut {
18+ shortcutTranslationKey : LocalizeKeys ;
19+ }
20+
21+ type ShortcutString = string | LocalizedShortcut ;
1922
2023interface Shortcut {
21- type : "shortcut" ;
2224 shortcut : ShortcutString [ ] ;
23- key : LocalizeKeys ;
25+ descriptionTranslationKey : LocalizeKeys ;
2426}
2527
2628interface Section {
27- key : LocalizeKeys ;
29+ titleTranslationKey : LocalizeKeys ;
2830 items : ( Text | Shortcut ) [ ] ;
2931}
3032
3133const CTRL_CMD = "__CTRL_CMD__" ;
3234
3335const _SHORTCUTS : Section [ ] = [
3436 {
35- key : "ui.dialogs.shortcuts.searching.title" ,
37+ titleTranslationKey : "ui.dialogs.shortcuts.searching.title" ,
3638 items : [
37- { type : "text" , key : "ui.dialogs.shortcuts.searching.on_any_page" } ,
3839 {
39- type : "shortcut" ,
40+ textTranslationKey : "ui.dialogs.shortcuts.searching.on_any_page" ,
41+ } ,
42+ {
4043 shortcut : [ "C" ] ,
41- key : "ui.dialogs.shortcuts.searching.search_command" ,
44+ descriptionTranslationKey :
45+ "ui.dialogs.shortcuts.searching.search_command" ,
4246 } ,
4347 {
44- type : "shortcut" ,
4548 shortcut : [ "E" ] ,
46- key : "ui.dialogs.shortcuts.searching.search_entities" ,
49+ descriptionTranslationKey :
50+ "ui.dialogs.shortcuts.searching.search_entities" ,
4751 } ,
4852 {
49- type : "shortcut" ,
5053 shortcut : [ "D" ] ,
51- key : "ui.dialogs.shortcuts.searching.search_devices" ,
54+ descriptionTranslationKey :
55+ "ui.dialogs.shortcuts.searching.search_devices" ,
5256 } ,
5357 {
54- type : "text" ,
55- key : "ui.dialogs.shortcuts.searching.on_pages_with_tables" ,
58+ textTranslationKey :
59+ "ui.dialogs.shortcuts.searching.on_pages_with_tables" ,
5660 } ,
5761 {
58- type : "shortcut" ,
5962 shortcut : [ CTRL_CMD , "F" ] ,
60- key : "ui.dialogs.shortcuts.searching.search_in_table" ,
63+ descriptionTranslationKey :
64+ "ui.dialogs.shortcuts.searching.search_in_table" ,
6165 } ,
6266 ] ,
6367 } ,
6468 {
65- key : "ui.dialogs.shortcuts.assist.title" ,
69+ titleTranslationKey : "ui.dialogs.shortcuts.assist.title" ,
6670 items : [
6771 {
68- type : "shortcut" ,
6972 shortcut : [ "A" ] ,
70- key : "ui.dialogs.shortcuts.assist.open_assist" ,
73+ descriptionTranslationKey : "ui.dialogs.shortcuts.assist.open_assist" ,
7174 } ,
7275 ] ,
7376 } ,
7477 {
75- key : "ui.dialogs.shortcuts.automation_script.title" ,
78+ titleTranslationKey : "ui.dialogs.shortcuts.automation_script.title" ,
7679 items : [
7780 {
78- type : "shortcut" ,
7981 shortcut : [ CTRL_CMD , "C" ] ,
80- key : "ui.dialogs.shortcuts.automation_script.copy" ,
82+ descriptionTranslationKey :
83+ "ui.dialogs.shortcuts.automation_script.copy" ,
8184 } ,
8285 {
83- type : "shortcut" ,
8486 shortcut : [ CTRL_CMD , "X" ] ,
85- key : "ui.dialogs.shortcuts.automation_script.cut" ,
87+ descriptionTranslationKey : "ui.dialogs.shortcuts.automation_script.cut" ,
8688 } ,
8789 {
88- type : "shortcut" ,
89- shortcut : [ CTRL_CMD , "del" ] ,
90- key : "ui.dialogs.shortcuts.automation_script.delete" ,
90+ shortcut : [
91+ CTRL_CMD ,
92+ { shortcutTranslationKey : "ui.dialogs.shortcuts.keys.del" } ,
93+ ] ,
94+ descriptionTranslationKey :
95+ "ui.dialogs.shortcuts.automation_script.delete" ,
9196 } ,
9297 {
93- type : "shortcut" ,
9498 shortcut : [ CTRL_CMD , "V" ] ,
95- key : "ui.dialogs.shortcuts.automation_script.paste" ,
99+ descriptionTranslationKey :
100+ "ui.dialogs.shortcuts.automation_script.paste" ,
96101 } ,
97102 {
98- type : "shortcut" ,
99103 shortcut : [ CTRL_CMD , "S" ] ,
100- key : "ui.dialogs.shortcuts.automation_script.save" ,
104+ descriptionTranslationKey :
105+ "ui.dialogs.shortcuts.automation_script.save" ,
101106 } ,
102107 ] ,
103108 } ,
104109 {
105- key : "ui.dialogs.shortcuts.charts.title" ,
110+ titleTranslationKey : "ui.dialogs.shortcuts.charts.title" ,
106111 items : [
107112 {
108- type : "shortcut" ,
109- shortcut : [ CTRL_CMD , { key : "ui.dialogs.shortcuts.shortcuts.drag" } ] ,
110- key : "ui.dialogs.shortcuts.charts.drag_to_zoom" ,
113+ shortcut : [
114+ CTRL_CMD ,
115+ { shortcutTranslationKey : "ui.dialogs.shortcuts.shortcuts.drag" } ,
116+ ] ,
117+ descriptionTranslationKey : "ui.dialogs.shortcuts.charts.drag_to_zoom" ,
111118 } ,
112119 {
113- type : "shortcut" ,
114120 shortcut : [
115121 CTRL_CMD ,
116- { key : "ui.dialogs.shortcuts.shortcuts.scroll_wheel" } ,
122+ {
123+ shortcutTranslationKey :
124+ "ui.dialogs.shortcuts.shortcuts.scroll_wheel" ,
125+ } ,
117126 ] ,
118- key : "ui.dialogs.shortcuts.charts.scroll_to_zoom" ,
127+ descriptionTranslationKey : "ui.dialogs.shortcuts.charts.scroll_to_zoom" ,
119128 } ,
120129 {
121- type : "shortcut" ,
122- shortcut : [ { key : "ui.dialogs.shortcuts.shortcuts.double_click" } ] ,
123- key : "ui.dialogs.shortcuts.charts.double_click" ,
130+ shortcut : [
131+ {
132+ shortcutTranslationKey :
133+ "ui.dialogs.shortcuts.shortcuts.double_click" ,
134+ } ,
135+ ] ,
136+ descriptionTranslationKey : "ui.dialogs.shortcuts.charts.double_click" ,
124137 } ,
125138 ] ,
126139 } ,
127140 {
128- key : "ui.dialogs.shortcuts.other.title" ,
141+ titleTranslationKey : "ui.dialogs.shortcuts.other.title" ,
129142 items : [
130143 {
131- type : "shortcut" ,
132144 shortcut : [ "M" ] ,
133- key : "ui.dialogs.shortcuts.other.my_link" ,
145+ descriptionTranslationKey : "ui.dialogs.shortcuts.other.my_link" ,
134146 } ,
135147 ] ,
136148 } ,
@@ -152,28 +164,28 @@ class DialogShortcuts extends LitElement {
152164 }
153165
154166 private _renderShortcut (
155- shortcuts : ShortcutString [ ] ,
156- translationKey : LocalizeKeys
167+ shortcutKeys : ShortcutString [ ] ,
168+ descriptionKey : LocalizeKeys
157169 ) {
158- const keys = shortcuts . map ( ( shortcut ) =>
159- typeof shortcut === "string" ? shortcut : this . hass . localize ( shortcut . key )
160- ) ;
161-
162170 return html `
163171 <div class= "shortcut" >
164- ${ keys . map (
165- ( key ) =>
172+ ${ shortcutKeys . map (
173+ ( shortcutKey ) =>
166174 html `<span
167- > ${ key === CTRL_CMD
175+ > ${ shortcutKey === CTRL_CMD
168176 ? isMac
169177 ? html `<ha- svg- icon
170178 .path = ${ mdiAppleKeyboardCommand }
171179 > </ ha- svg- icon> `
172180 : this . hass . localize ( "ui.panel.config.automation.editor.ctrl" )
173- : key } </ span
181+ : typeof shortcutKey === "string"
182+ ? shortcutKey
183+ : this . hass . localize (
184+ shortcutKey . shortcutTranslationKey
185+ ) } </ span
174186 > `
175187 ) }
176- ${ this . hass . localize ( translationKey ) }
188+ ${ this . hass . localize ( descriptionKey ) }
177189 </ div>
178190 ` ;
179191 }
@@ -197,16 +209,18 @@ class DialogShortcuts extends LitElement {
197209 <div class= "content" >
198210 ${ _SHORTCUTS . map (
199211 ( section ) => html `
200- <h3> ${ this . hass . localize ( section . key ) } </ h3>
212+ <h3> ${ this . hass . localize ( section . titleTranslationKey ) } </ h3>
201213 <div class= "items" >
202214 ${ section . items . map ( ( item ) => {
203- if ( item . type === "text" ) {
204- return html `<p > ${ this . hass . localize ( item . key ) } < / p > ` ;
205- }
206- if ( item . type === "shortcut" ) {
207- return this . _renderShortcut ( item . shortcut , item . key ) ;
215+ if ( "shortcut" in item ) {
216+ return this . _renderShortcut (
217+ ( item as Shortcut ) . shortcut ,
218+ ( item as Shortcut ) . descriptionTranslationKey
219+ ) ;
208220 }
209- return nothing ;
221+ return html `<p>
222+ ${ this . hass . localize ( ( item as Text ) . textTranslationKey ) }
223+ </ p> ` ;
210224 } ) }
211225 </ div>
212226 `
0 commit comments