mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Use translations for config entry reason (#8981)
This commit is contained in:
parent
ac9a881ab5
commit
24e202a3d7
@ -79,7 +79,11 @@ const setupRetryEntry = createConfigEntry("Setup Retry", {
|
|||||||
});
|
});
|
||||||
const setupRetryReasonEntry = createConfigEntry("Setup Retry", {
|
const setupRetryReasonEntry = createConfigEntry("Setup Retry", {
|
||||||
state: "setup_retry",
|
state: "setup_retry",
|
||||||
reason: "Unable to connect",
|
reason: "connection_error",
|
||||||
|
});
|
||||||
|
const setupRetryReasonMissingKeyEntry = createConfigEntry("Setup Retry", {
|
||||||
|
state: "setup_retry",
|
||||||
|
reason: "resolve_error",
|
||||||
});
|
});
|
||||||
const failedUnloadEntry = createConfigEntry("Failed Unload", {
|
const failedUnloadEntry = createConfigEntry("Failed Unload", {
|
||||||
state: "failed_unload",
|
state: "failed_unload",
|
||||||
@ -141,6 +145,7 @@ const configEntries: Array<{
|
|||||||
{ items: [migrationErrorEntry] },
|
{ items: [migrationErrorEntry] },
|
||||||
{ items: [setupRetryEntry] },
|
{ items: [setupRetryEntry] },
|
||||||
{ items: [setupRetryReasonEntry] },
|
{ items: [setupRetryReasonEntry] },
|
||||||
|
{ items: [setupRetryReasonMissingKeyEntry] },
|
||||||
{ items: [failedUnloadEntry] },
|
{ items: [failedUnloadEntry] },
|
||||||
{ items: [notLoadedEntry] },
|
{ items: [notLoadedEntry] },
|
||||||
{
|
{
|
||||||
@ -298,6 +303,14 @@ export class DemoIntegrationCard extends LitElement {
|
|||||||
const hass = provideHass(this);
|
const hass = provideHass(this);
|
||||||
hass.updateTranslations(null, "en");
|
hass.updateTranslations(null, "en");
|
||||||
hass.updateTranslations("config", "en");
|
hass.updateTranslations("config", "en");
|
||||||
|
// Normally this string is loaded from backend
|
||||||
|
hass.addTranslations(
|
||||||
|
{
|
||||||
|
"component.esphome.config.error.connection_error":
|
||||||
|
"Can't connect to ESP. Please make sure your YAML file contains an 'api:' line.",
|
||||||
|
},
|
||||||
|
"en"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _toggleCustomIntegration() {
|
private _toggleCustomIntegration() {
|
||||||
|
@ -30,6 +30,7 @@ export interface MockHomeAssistant extends HomeAssistant {
|
|||||||
updateStates(newStates: HassEntities);
|
updateStates(newStates: HassEntities);
|
||||||
addEntities(entites: Entity | Entity[], replace?: boolean);
|
addEntities(entites: Entity | Entity[], replace?: boolean);
|
||||||
updateTranslations(fragment: null | string, language?: string);
|
updateTranslations(fragment: null | string, language?: string);
|
||||||
|
addTranslations(translations: Record<string, string>, language?: string);
|
||||||
mockWS(
|
mockWS(
|
||||||
type: string,
|
type: string,
|
||||||
callback: (msg: any, onChange?: (response: any) => void) => any
|
callback: (msg: any, onChange?: (response: any) => void) => any
|
||||||
@ -60,15 +61,25 @@ export const provideHass = (
|
|||||||
) {
|
) {
|
||||||
const lang = language || getLocalLanguage();
|
const lang = language || getLocalLanguage();
|
||||||
const translation = await getTranslation(fragment, lang);
|
const translation = await getTranslation(fragment, lang);
|
||||||
|
await addTranslations(translation.data, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addTranslations(
|
||||||
|
translations: Record<string, string>,
|
||||||
|
language?: string
|
||||||
|
) {
|
||||||
|
const lang = language || getLocalLanguage();
|
||||||
const resources = {
|
const resources = {
|
||||||
[lang]: {
|
[lang]: {
|
||||||
...(hass().resources && hass().resources[lang]),
|
...(hass().resources && hass().resources[lang]),
|
||||||
...translation.data,
|
...translations,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
hass().updateHass({
|
hass().updateHass({
|
||||||
resources,
|
resources,
|
||||||
localize: await computeLocalize(elements[0], lang, resources),
|
});
|
||||||
|
hass().updateHass({
|
||||||
|
localize: await computeLocalize(elements[0], lang, hass().resources),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +220,9 @@ export const provideHass = (
|
|||||||
localize: () => "",
|
localize: () => "",
|
||||||
|
|
||||||
translationMetadata: translationMetadata as any,
|
translationMetadata: translationMetadata as any,
|
||||||
|
async loadBackendTranslation() {
|
||||||
|
return hass().localize;
|
||||||
|
},
|
||||||
dockedSidebar: "auto",
|
dockedSidebar: "auto",
|
||||||
vibrate: true,
|
vibrate: true,
|
||||||
suspendWhenHidden: false,
|
suspendWhenHidden: false,
|
||||||
@ -250,6 +264,7 @@ export const provideHass = (
|
|||||||
},
|
},
|
||||||
updateStates,
|
updateStates,
|
||||||
updateTranslations,
|
updateTranslations,
|
||||||
|
addTranslations,
|
||||||
addEntities,
|
addEntities,
|
||||||
mockWS(type, callback) {
|
mockWS(type, callback) {
|
||||||
wsCommands[type] = callback;
|
wsCommands[type] = callback;
|
||||||
|
@ -199,9 +199,14 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
stateText = [
|
stateText = [
|
||||||
`ui.panel.config.integrations.config_entry.state.${item.state}`,
|
`ui.panel.config.integrations.config_entry.state.${item.state}`,
|
||||||
];
|
];
|
||||||
stateTextExtra = item.reason
|
if (item.reason) {
|
||||||
? html`: ${item.reason}`
|
this.hass.loadBackendTranslation("config", item.domain);
|
||||||
: html`
|
stateTextExtra = html`:
|
||||||
|
${this.hass.localize(
|
||||||
|
`component.${item.domain}.config.error.${item.reason}`
|
||||||
|
) || item.reason}`;
|
||||||
|
} else {
|
||||||
|
stateTextExtra = html`
|
||||||
<br />
|
<br />
|
||||||
<a href="/config/logs"
|
<a href="/config/logs"
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
@ -210,6 +215,7 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
>
|
>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${stateText
|
${stateText
|
||||||
|
@ -2179,7 +2179,7 @@
|
|||||||
"loaded": "Loaded",
|
"loaded": "Loaded",
|
||||||
"setup_error": "Failed to set up",
|
"setup_error": "Failed to set up",
|
||||||
"migration_error": "Migration error",
|
"migration_error": "Migration error",
|
||||||
"setup_retry": "Retrying to set up",
|
"setup_retry": "Retrying setup",
|
||||||
"not_loaded": "Not loaded",
|
"not_loaded": "Not loaded",
|
||||||
"failed_unload": "Failed to unload"
|
"failed_unload": "Failed to unload"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user