1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 08:33:31 +01:00

Add translation support for nested app configuration schemas (#30121)

This commit is contained in:
Niklas Wagner
2026-03-22 10:38:36 +01:00
committed by GitHub
parent ed75d96d3c
commit 2fec5a497e
2 changed files with 59 additions and 13 deletions

View File

@@ -257,6 +257,7 @@ export class HaObjectSelector extends LitElement {
schema: this._schema(this.selector),
data: item,
computeLabel: this._computeLabel,
computeHelper: this._computeHelper,
submitText: this.hass.localize("ui.common.save"),
});

View File

@@ -115,26 +115,51 @@ class SupervisorAppConfig extends LitElement {
private _convertSchema = memoizeOne(
// Convert supervisor schema to selectors
(schema: readonly HaFormSchema[]): HaFormSchema[] =>
this._convertSchemaElements(schema)
(
schema: readonly HaFormSchema[],
language: string,
translations: HassioAddonDetails["translations"]
): HaFormSchema[] =>
this._convertSchemaElements(schema, language, translations)
);
private _convertSchemaElements(
schema: readonly HaFormSchema[]
schema: readonly HaFormSchema[],
language: string,
translations: HassioAddonDetails["translations"],
path: string[] = []
): HaFormSchema[] {
return schema.map((entry) => this._convertSchemaElement(entry));
return schema.map((entry) =>
this._convertSchemaElement(entry, language, translations, path)
);
}
private _convertSchemaElement(entry: any): HaFormSchema {
private _convertSchemaElement(
entry: any,
language: string,
translations: HassioAddonDetails["translations"],
path: string[]
): HaFormSchema {
if (entry.type === "schema" && !entry.multiple) {
return {
name: entry.name,
type: "expandable",
required: entry.required,
schema: this._convertSchemaElements(entry.schema),
schema: this._convertSchemaElements(
entry.schema,
language,
translations,
[...path, entry.name]
),
};
}
const selector = this._convertSchemaElementToSelector(entry, false);
const selector = this._convertSchemaElementToSelector(
entry,
false,
language,
translations,
path
);
if (selector) {
return {
name: entry.name,
@@ -147,7 +172,10 @@ class SupervisorAppConfig extends LitElement {
private _convertSchemaElementToSelector(
entry: any,
force: boolean
force: boolean,
language: string,
translations: HassioAddonDetails["translations"],
path: string[]
): Selector | null {
if (entry.type === "select") {
return { select: { options: entry.options } };
@@ -170,10 +198,25 @@ class SupervisorAppConfig extends LitElement {
}
if (entry.type === "schema") {
const fields: NonNullable<ObjectSelector["object"]>["fields"] = {};
for (const child_entry of entry.schema) {
fields[child_entry.name] = {
required: child_entry.required,
selector: this._convertSchemaElementToSelector(child_entry, true)!,
const childPath = [...path, entry.name];
for (const childEntry of entry.schema) {
const translation =
this._getTranslationEntry(language, childEntry, {
path: childPath,
}) ||
this._getTranslationEntry("en", childEntry, { path: childPath });
fields[childEntry.name] = {
required: childEntry.required,
label: translation?.name,
description: translation?.description,
selector: this._convertSchemaElementToSelector(
childEntry,
true,
language,
translations,
childPath
)!,
};
}
return {
@@ -267,7 +310,9 @@ class SupervisorAppConfig extends LitElement {
: this._filteredSchema(
this.addon.options,
this.addon.schema!
)
),
this.hass.language,
this.addon.translations
)}
></ha-form>`
: html`<ha-yaml-editor