Skip to content

Commit

Permalink
fix translations
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Dec 6, 2024
1 parent 589f55b commit 7bdb01e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
6 changes: 5 additions & 1 deletion src/data/data_entry_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Connection } from "home-assistant-js-websocket";
import type { HaFormSchema } from "../components/ha-form/types";
import type { ConfigEntry } from "./config_entries";

export type FlowType = "config_flow" | "options_flow" | "repair_flow";
export type FlowType =
| "config_flow"
| "config_subentries_flow"
| "options_flow"
| "repair_flow";

export interface DataEntryFlowProgressedEvent {
type: "data_entry_flow_progressed";
Expand Down
1 change: 1 addition & 0 deletions src/data/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type TranslationCategory =
| "entity_component"
| "exceptions"
| "config"
| "config_subentries"
| "config_panel"
| "options"
| "device_automation"
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/config-flow/previews/flow-preview-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class FlowPreviewGeneric extends LitElement {
(await this._unsub)();
this._unsub = undefined;
}
if (this.flowType === "repair_flow") {
if (this.flowType !== "config_flow" && this.flowType !== "options_flow") {
return;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/config-flow/previews/flow-preview-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class FlowPreviewTemplate extends LitElement {
(await this._unsub)();
this._unsub = undefined;
}
if (this.flowType === "repair_flow") {
if (this.flowType !== "config_flow" && this.flowType !== "options_flow") {
return;
}
try {
Expand Down
63 changes: 34 additions & 29 deletions src/dialogs/config-flow/show-dialog-sub-config-flow.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { html } from "lit";
import type { ConfigEntry } from "../../data/config_entries";
import { domainToName } from "../../data/integration";
import {
createSubConfigFlow,
deleteSubConfigFlow,
fetchSubConfigFlow,
handleSubConfigFlowStep,
} from "../../data/sub_config_flow";
import { domainToName } from "../../data/integration";
import type { DataEntryFlowDialogParams } from "./show-dialog-data-entry-flow";
import {
loadDataEntryFlowDialog,
Expand All @@ -16,35 +17,39 @@ export const loadSubConfigFlowDialog = loadDataEntryFlowDialog;

export const showSubConfigFlowDialog = (
element: HTMLElement,
configEntry: ConfigEntry,
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig">
): void =>
showFlowDialog(element, dialogParams, {
flowType: "config_flow",
flowType: "config_subentries_flow",
showDevices: true,
createFlow: async (hass, handler) => {
const [step] = await Promise.all([
createSubConfigFlow(hass, handler, dialogParams.entryId),
hass.loadFragmentTranslation("config"),
hass.loadBackendTranslation("config", handler),
hass.loadBackendTranslation("selector", handler),
hass.loadBackendTranslation("config_subentries", configEntry.domain),
hass.loadBackendTranslation("selector", configEntry.domain),
// Used as fallback if no header defined for step
hass.loadBackendTranslation("title", handler),
hass.loadBackendTranslation("title", configEntry.domain),
]);
return step;
},
fetchFlow: async (hass, flowId) => {
const step = await fetchSubConfigFlow(hass, flowId);
await hass.loadFragmentTranslation("config");
await hass.loadBackendTranslation("config", step.handler);
await hass.loadBackendTranslation("selector", step.handler);
await hass.loadBackendTranslation(
"config_subentries",
configEntry.domain
);
await hass.loadBackendTranslation("selector", configEntry.domain);
return step;
},
handleFlowStep: handleSubConfigFlowStep,
deleteFlow: deleteSubConfigFlow,

renderAbortDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.abort.${step.reason}`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.abort.${step.reason}`,
step.description_placeholders
);

Expand All @@ -58,15 +63,15 @@ export const showSubConfigFlowDialog = (
renderShowFormStepHeader(hass, step) {
return (
hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.title`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.title`,
step.description_placeholders
) || hass.localize(`component.${step.handler}.title`)
) || hass.localize(`component.${configEntry.domain}.title`)
);
},

renderShowFormStepDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.description`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.description`,
step.description_placeholders
);
return description
Expand All @@ -79,30 +84,30 @@ export const showSubConfigFlowDialog = (
renderShowFormStepFieldLabel(hass, step, field, options) {
if (field.type === "expandable") {
return hass.localize(
`component.${step.handler}.config.step.${step.step_id}.sections.${field.name}.name`
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.sections.${field.name}.name`
);
}

const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";

return (
hass.localize(
`component.${step.handler}.config.step.${step.step_id}.${prefix}data.${field.name}`
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.${prefix}data.${field.name}`
) || field.name
);
},

renderShowFormStepFieldHelper(hass, step, field, options) {
if (field.type === "expandable") {
return hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.sections.${field.name}.description`
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.sections.${field.name}.description`
);
}

const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";

const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.${prefix}data_description.${field.name}`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.${prefix}data_description.${field.name}`,
step.description_placeholders
);

Expand All @@ -114,20 +119,20 @@ export const showSubConfigFlowDialog = (
renderShowFormStepFieldError(hass, step, error) {
return (
hass.localize(
`component.${step.translation_domain || step.translation_domain || step.handler}.config.error.${error}`,
`component.${step.translation_domain || step.translation_domain || configEntry.domain}.config_subentries.error.${error}`,
step.description_placeholders
) || error
);
},

renderShowFormStepFieldLocalizeValue(hass, step, key) {
return hass.localize(`component.${step.handler}.selector.${key}`);
renderShowFormStepFieldLocalizeValue(hass, _step, key) {
return hass.localize(`component.${configEntry.domain}.selector.${key}`);
},

renderShowFormStepSubmitButton(hass, step) {
return (
hass.localize(
`component.${step.handler}.config.step.${step.step_id}.submit`
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.submit`
) ||
hass.localize(
`ui.panel.config.integrations.config_flow.${
Expand All @@ -140,7 +145,7 @@ export const showSubConfigFlowDialog = (
renderExternalStepHeader(hass, step) {
return (
hass.localize(
`component.${step.handler}.config.step.${step.step_id}.title`
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.title`
) ||
hass.localize(
"ui.panel.config.integrations.config_flow.external_step.open_site"
Expand All @@ -150,7 +155,7 @@ export const showSubConfigFlowDialog = (

renderExternalStepDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.${step.step_id}.description`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.${step.step_id}.description`,
step.description_placeholders
);

Expand All @@ -174,7 +179,7 @@ export const showSubConfigFlowDialog = (

renderCreateEntryDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.create_entry.${
`component.${step.translation_domain || configEntry.domain}.config_subentries.create_entry.${
step.description || "default"
}`,
step.description_placeholders
Expand Down Expand Up @@ -202,14 +207,14 @@ export const showSubConfigFlowDialog = (
renderShowFormProgressHeader(hass, step) {
return (
hass.localize(
`component.${step.handler}.config.step.${step.step_id}.title`
) || hass.localize(`component.${step.handler}.title`)
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.title`
) || hass.localize(`component.${configEntry.domain}.title`)
);
},

renderShowFormProgressDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.progress.${step.progress_action}`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.progress.${step.progress_action}`,
step.description_placeholders
);
return description
Expand All @@ -222,14 +227,14 @@ export const showSubConfigFlowDialog = (
renderMenuHeader(hass, step) {
return (
hass.localize(
`component.${step.handler}.config.step.${step.step_id}.title`
) || hass.localize(`component.${step.handler}.title`)
`component.${configEntry.domain}.config_subentries.step.${step.step_id}.title`
) || hass.localize(`component.${configEntry.domain}.title`)
);
},

renderMenuDescription(hass, step) {
const description = hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.description`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.description`,
step.description_placeholders
);
return description
Expand All @@ -241,7 +246,7 @@ export const showSubConfigFlowDialog = (

renderMenuOption(hass, step, option) {
return hass.localize(
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.menu_options.${option}`,
`component.${step.translation_domain || configEntry.domain}.config_subentries.step.${step.step_id}.menu_options.${option}`,
step.description_placeholders
);
},
Expand Down
6 changes: 3 additions & 3 deletions src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
${item.supports_subentries
? html`<ha-md-menu-item
@click=${this._addSubEntry}
.entryId=${item.entry_id}
.entry=${item}
graphic="icon"
>
<ha-svg-icon slot="start" .path=${mdiPlus}></ha-svg-icon>
Expand Down Expand Up @@ -1589,8 +1589,8 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
}

private async _addSubEntry(ev) {
showSubConfigFlowDialog(this, {
startFlowHandler: ev.target.entryId,
showSubConfigFlowDialog(this, ev.target.entry, {
startFlowHandler: ev.target.entry.entry_id,
});
}

Expand Down

0 comments on commit 7bdb01e

Please sign in to comment.