mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 22:06:34 +00:00
Separate supervisor localize key exceptions and disallow string (#13317)
This commit is contained in:
parent
150bc00c31
commit
1d47303127
@ -176,7 +176,7 @@ export class HassioBackups extends LitElement {
|
|||||||
: supervisorTabs(this.hass)}
|
: supervisorTabs(this.hass)}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.localizeFunc=${this.supervisor.localize}
|
.localizeFunc=${this.supervisor.localize}
|
||||||
.searchLabel=${this.supervisor.localize("search")}
|
.searchLabel=${this.supervisor.localize("backup.search")}
|
||||||
.noDataText=${this.supervisor.localize("backup.no_backups")}
|
.noDataText=${this.supervisor.localize("backup.no_backups")}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
@ -240,7 +240,7 @@ export class HassioBackups extends LitElement {
|
|||||||
: html`
|
: html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.label=${this.supervisor.localize(
|
.label=${this.supervisor.localize(
|
||||||
"snapshot.delete_selected"
|
"backup.delete_selected"
|
||||||
)}
|
)}
|
||||||
.path=${mdiDelete}
|
.path=${mdiDelete}
|
||||||
id="delete-btn"
|
id="delete-btn"
|
||||||
|
@ -22,10 +22,11 @@ import {
|
|||||||
Supervisor,
|
Supervisor,
|
||||||
SupervisorObject,
|
SupervisorObject,
|
||||||
supervisorCollection,
|
supervisorCollection,
|
||||||
|
SupervisorKeys,
|
||||||
} from "../../src/data/supervisor/supervisor";
|
} from "../../src/data/supervisor/supervisor";
|
||||||
import { ProvideHassLitMixin } from "../../src/mixins/provide-hass-lit-mixin";
|
import { ProvideHassLitMixin } from "../../src/mixins/provide-hass-lit-mixin";
|
||||||
import { urlSyncMixin } from "../../src/state/url-sync-mixin";
|
import { urlSyncMixin } from "../../src/state/url-sync-mixin";
|
||||||
import { HomeAssistant, Route, TranslationDict } from "../../src/types";
|
import { HomeAssistant, Route } from "../../src/types";
|
||||||
import { getTranslation } from "../../src/util/common-translation";
|
import { getTranslation } from "../../src/util/common-translation";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -124,7 +125,7 @@ export class SupervisorBaseElement extends urlSyncMixin(
|
|||||||
|
|
||||||
this.supervisor = {
|
this.supervisor = {
|
||||||
...this.supervisor,
|
...this.supervisor,
|
||||||
localize: await computeLocalize<TranslationDict["supervisor"]>(
|
localize: await computeLocalize<SupervisorKeys>(
|
||||||
this.constructor.prototype,
|
this.constructor.prototype,
|
||||||
language,
|
language,
|
||||||
{
|
{
|
||||||
|
@ -9,18 +9,18 @@ import { getLocalLanguage } from "../../util/common-translation";
|
|||||||
// Exclude some patterns from key type checking for now
|
// Exclude some patterns from key type checking for now
|
||||||
// These are intended to be removed as errors are fixed
|
// These are intended to be removed as errors are fixed
|
||||||
// Fixing component category will require tighter definition of types from backend and/or web socket
|
// Fixing component category will require tighter definition of types from backend and/or web socket
|
||||||
type LocalizeKeyExceptions =
|
export type LocalizeKeys =
|
||||||
|
| FlattenObjectKeys<Omit<TranslationDict, "supervisor">>
|
||||||
| `${string}`
|
| `${string}`
|
||||||
| `panel.${string}`
|
| `panel.${string}`
|
||||||
| `state.${string}`
|
| `state.${string}`
|
||||||
| `state_attributes.${string}`
|
| `state_attributes.${string}`
|
||||||
| `state_badge.${string}`
|
| `state_badge.${string}`
|
||||||
| `ui.${string}`
|
| `ui.${string}`
|
||||||
| `${keyof TranslationDict["supervisor"]}.${string}`
|
|
||||||
| `component.${string}`;
|
| `component.${string}`;
|
||||||
|
|
||||||
// Tweaked from https://www.raygesualdo.com/posts/flattening-object-keys-with-typescript-types
|
// Tweaked from https://www.raygesualdo.com/posts/flattening-object-keys-with-typescript-types
|
||||||
type FlattenObjectKeys<
|
export type FlattenObjectKeys<
|
||||||
T extends Record<string, any>,
|
T extends Record<string, any>,
|
||||||
Key extends keyof T = keyof T
|
Key extends keyof T = keyof T
|
||||||
> = Key extends string
|
> = Key extends string
|
||||||
@ -29,10 +29,8 @@ type FlattenObjectKeys<
|
|||||||
: `${Key}`
|
: `${Key}`
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export type LocalizeFunc<
|
export type LocalizeFunc<Keys extends string = LocalizeKeys> = (
|
||||||
Dict extends Record<string, unknown> = TranslationDict
|
key: Keys,
|
||||||
> = (
|
|
||||||
key: FlattenObjectKeys<Dict> | LocalizeKeyExceptions,
|
|
||||||
...args: any[]
|
...args: any[]
|
||||||
) => string;
|
) => string;
|
||||||
|
|
||||||
@ -94,14 +92,12 @@ export const polyfillsLoaded =
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const computeLocalize = async <
|
export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
||||||
Dict extends Record<string, unknown> = TranslationDict
|
|
||||||
>(
|
|
||||||
cache: any,
|
cache: any,
|
||||||
language: string,
|
language: string,
|
||||||
resources: Resources,
|
resources: Resources,
|
||||||
formats?: FormatsType
|
formats?: FormatsType
|
||||||
): Promise<LocalizeFunc<Dict>> => {
|
): Promise<LocalizeFunc<Keys>> => {
|
||||||
if (polyfillsLoaded) {
|
if (polyfillsLoaded) {
|
||||||
await polyfillsLoaded;
|
await polyfillsLoaded;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { Connection, getCollection } from "home-assistant-js-websocket";
|
import { Connection, getCollection } from "home-assistant-js-websocket";
|
||||||
import { Store } from "home-assistant-js-websocket/dist/store";
|
import { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
import { LocalizeFunc } from "../../common/translations/localize";
|
import {
|
||||||
|
FlattenObjectKeys,
|
||||||
|
LocalizeFunc,
|
||||||
|
} from "../../common/translations/localize";
|
||||||
import { HomeAssistant, TranslationDict } from "../../types";
|
import { HomeAssistant, TranslationDict } from "../../types";
|
||||||
import { HassioAddonsInfo } from "../hassio/addon";
|
import { HassioAddonsInfo } from "../hassio/addon";
|
||||||
import { HassioHassOSInfo, HassioHostInfo } from "../hassio/host";
|
import { HassioHassOSInfo, HassioHostInfo } from "../hassio/host";
|
||||||
@ -57,6 +60,10 @@ export interface SupervisorEvent {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SupervisorKeys =
|
||||||
|
| FlattenObjectKeys<TranslationDict["supervisor"]>
|
||||||
|
| `${keyof TranslationDict["supervisor"]}.${string}`;
|
||||||
|
|
||||||
export interface Supervisor {
|
export interface Supervisor {
|
||||||
host: HassioHostInfo;
|
host: HassioHostInfo;
|
||||||
supervisor: HassioSupervisorInfo;
|
supervisor: HassioSupervisorInfo;
|
||||||
@ -67,7 +74,7 @@ export interface Supervisor {
|
|||||||
os: HassioHassOSInfo;
|
os: HassioHassOSInfo;
|
||||||
addon: HassioAddonsInfo;
|
addon: HassioAddonsInfo;
|
||||||
store: SupervisorStore;
|
store: SupervisorStore;
|
||||||
localize: LocalizeFunc<TranslationDict["supervisor"]>;
|
localize: LocalizeFunc<SupervisorKeys>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const supervisorApiWsRequest = <T>(
|
export const supervisorApiWsRequest = <T>(
|
||||||
|
@ -4955,6 +4955,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"backup": {
|
"backup": {
|
||||||
|
"search": "[%key:ui::panel::config::backup::picker::search%]",
|
||||||
"no_backups": "You don't have any backups yet.",
|
"no_backups": "You don't have any backups yet.",
|
||||||
"create_blocked_not_running": "Creating a backup is not possible right now because the system is in {state} state.",
|
"create_blocked_not_running": "Creating a backup is not possible right now because the system is in {state} state.",
|
||||||
"delete_selected": "Delete selected backups",
|
"delete_selected": "Delete selected backups",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user