From 841b9c0917a7c7efed7a31a77a08a4728ff7118e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 28 Feb 2024 11:12:19 +0100 Subject: [PATCH] Add support for translation domain in data entry flows (#19900) --- src/data/data_entry_flow.ts | 6 ++++++ .../config-flow/show-dialog-config-flow.ts | 20 +++++++++---------- .../config-flow/show-dialog-options-flow.ts | 16 +++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/data/data_entry_flow.ts b/src/data/data_entry_flow.ts index 7a830e7d88..d60e55beab 100644 --- a/src/data/data_entry_flow.ts +++ b/src/data/data_entry_flow.ts @@ -33,6 +33,7 @@ export interface DataEntryFlowStepForm { description_placeholders?: Record; last_step: boolean | null; preview?: string; + translation_domain?: string; } export interface DataEntryFlowStepExternal { @@ -42,6 +43,7 @@ export interface DataEntryFlowStepExternal { step_id: string; url: string; description_placeholders: Record; + translation_domain?: string; } export interface DataEntryFlowStepCreateEntry { @@ -53,6 +55,7 @@ export interface DataEntryFlowStepCreateEntry { result?: ConfigEntry; description: string; description_placeholders?: Record; + translation_domain?: string; } export interface DataEntryFlowStepAbort { @@ -61,6 +64,7 @@ export interface DataEntryFlowStepAbort { handler: string; reason: string; description_placeholders?: Record; + translation_domain?: string; } export interface DataEntryFlowStepProgress { @@ -70,6 +74,7 @@ export interface DataEntryFlowStepProgress { step_id: string; progress_action: string; description_placeholders?: Record; + translation_domain?: string; } export interface DataEntryFlowStepMenu { @@ -80,6 +85,7 @@ export interface DataEntryFlowStepMenu { /** If array, use value to lookup translations in strings.json */ menu_options: string[] | Record; description_placeholders?: Record; + translation_domain?: string; } export type DataEntryFlowStep = diff --git a/src/dialogs/config-flow/show-dialog-config-flow.ts b/src/dialogs/config-flow/show-dialog-config-flow.ts index 9ccc581840..8b2b6b1667 100644 --- a/src/dialogs/config-flow/show-dialog-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-config-flow.ts @@ -44,7 +44,7 @@ export const showConfigFlowDialog = ( renderAbortDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.abort.${step.reason}`, + `component.${step.translation_domain || step.handler}.config.abort.${step.reason}`, step.description_placeholders ); @@ -58,7 +58,7 @@ export const showConfigFlowDialog = ( renderShowFormStepHeader(hass, step) { return ( hass.localize( - `component.${step.handler}.config.step.${step.step_id}.title`, + `component.${step.translation_domain || step.handler}.config.step.${step.step_id}.title`, step.description_placeholders ) || hass.localize(`component.${step.handler}.title`) ); @@ -66,7 +66,7 @@ export const showConfigFlowDialog = ( renderShowFormStepDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.step.${step.step_id}.description`, + `component.${step.translation_domain || step.handler}.config.step.${step.step_id}.description`, step.description_placeholders ); return description @@ -84,7 +84,7 @@ export const showConfigFlowDialog = ( renderShowFormStepFieldHelper(hass, step, field) { const description = hass.localize( - `component.${step.handler}.config.step.${step.step_id}.data_description.${field.name}`, + `component.${step.translation_domain || step.handler}.config.step.${step.step_id}.data_description.${field.name}`, step.description_placeholders ); return description @@ -95,7 +95,7 @@ export const showConfigFlowDialog = ( renderShowFormStepFieldError(hass, step, error) { return ( hass.localize( - `component.${step.handler}.config.error.${error}`, + `component.${step.translation_domain || step.translation_domain || step.handler}.config.error.${error}`, step.description_placeholders ) || error ); @@ -131,7 +131,7 @@ export const showConfigFlowDialog = ( renderExternalStepDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.${step.step_id}.description`, + `component.${step.translation_domain || step.handler}.config.${step.step_id}.description`, step.description_placeholders ); @@ -155,7 +155,7 @@ export const showConfigFlowDialog = ( renderCreateEntryDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.create_entry.${ + `component.${step.translation_domain || step.handler}.config.create_entry.${ step.description || "default" }`, step.description_placeholders @@ -190,7 +190,7 @@ export const showConfigFlowDialog = ( renderShowFormProgressDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.progress.${step.progress_action}`, + `component.${step.translation_domain || step.handler}.config.progress.${step.progress_action}`, step.description_placeholders ); return description @@ -210,7 +210,7 @@ export const showConfigFlowDialog = ( renderMenuDescription(hass, step) { const description = hass.localize( - `component.${step.handler}.config.step.${step.step_id}.description`, + `component.${step.translation_domain || step.handler}.config.step.${step.step_id}.description`, step.description_placeholders ); return description @@ -222,7 +222,7 @@ export const showConfigFlowDialog = ( renderMenuOption(hass, step, option) { return hass.localize( - `component.${step.handler}.config.step.${step.step_id}.menu_options.${option}`, + `component.${step.translation_domain || step.handler}.config.step.${step.step_id}.menu_options.${option}`, step.description_placeholders ); }, diff --git a/src/dialogs/config-flow/show-dialog-options-flow.ts b/src/dialogs/config-flow/show-dialog-options-flow.ts index 05f3acc1b4..491df7e91f 100644 --- a/src/dialogs/config-flow/show-dialog-options-flow.ts +++ b/src/dialogs/config-flow/show-dialog-options-flow.ts @@ -53,7 +53,7 @@ export const showOptionsFlowDialog = ( renderAbortDescription(hass, step) { const description = hass.localize( - `component.${configEntry.domain}.options.abort.${step.reason}`, + `component.${step.translation_domain || configEntry.domain}.options.abort.${step.reason}`, step.description_placeholders ); @@ -71,7 +71,7 @@ export const showOptionsFlowDialog = ( renderShowFormStepHeader(hass, step) { return ( hass.localize( - `component.${configEntry.domain}.options.step.${step.step_id}.title`, + `component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.title`, step.description_placeholders ) || hass.localize(`ui.dialogs.options_flow.form.header`) ); @@ -79,7 +79,7 @@ export const showOptionsFlowDialog = ( renderShowFormStepDescription(hass, step) { const description = hass.localize( - `component.${configEntry.domain}.options.step.${step.step_id}.description`, + `component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.description`, step.description_placeholders ); return description @@ -101,7 +101,7 @@ export const showOptionsFlowDialog = ( renderShowFormStepFieldHelper(hass, step, field) { const description = hass.localize( - `component.${configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`, + `component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`, step.description_placeholders ); return description @@ -112,7 +112,7 @@ export const showOptionsFlowDialog = ( renderShowFormStepFieldError(hass, step, error) { return ( hass.localize( - `component.${configEntry.domain}.options.error.${error}`, + `component.${step.translation_domain || configEntry.domain}.options.error.${error}`, step.description_placeholders ) || error ); @@ -159,7 +159,7 @@ export const showOptionsFlowDialog = ( renderShowFormProgressDescription(hass, step) { const description = hass.localize( - `component.${configEntry.domain}.options.progress.${step.progress_action}`, + `component.${step.translation_domain || configEntry.domain}.options.progress.${step.progress_action}`, step.description_placeholders ); return description @@ -183,7 +183,7 @@ export const showOptionsFlowDialog = ( renderMenuDescription(hass, step) { const description = hass.localize( - `component.${configEntry.domain}.options.step.${step.step_id}.description`, + `component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.description`, step.description_placeholders ); return description @@ -199,7 +199,7 @@ export const showOptionsFlowDialog = ( renderMenuOption(hass, step, option) { return hass.localize( - `component.${configEntry.domain}.options.step.${step.step_id}.menu_options.${option}`, + `component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.menu_options.${option}`, step.description_placeholders ); },