mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Fix generated Lovelace translating domain names (#5803)
This commit is contained in:
parent
60be14dc77
commit
6d0823328d
@ -60,6 +60,7 @@ import type {
|
|||||||
import { HASSDomEvent } from "../../../common/dom/fire_event";
|
import { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import { mdiPlus } from "@mdi/js";
|
import { mdiPlus } from "@mdi/js";
|
||||||
|
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
|
|
||||||
interface DataEntryFlowProgressExtended extends DataEntryFlowProgress {
|
interface DataEntryFlowProgressExtended extends DataEntryFlowProgress {
|
||||||
localized_title?: string;
|
localized_title?: string;
|
||||||
@ -121,7 +122,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
this._deviceRegistryEntries = entries;
|
this._deviceRegistryEntries = entries;
|
||||||
}),
|
}),
|
||||||
subscribeConfigFlowInProgress(this.hass, async (flowsInProgress) => {
|
subscribeConfigFlowInProgress(this.hass, async (flowsInProgress) => {
|
||||||
const translationsPromisses: Promise<void>[] = [];
|
const translationsPromisses: Promise<LocalizeFunc>[] = [];
|
||||||
flowsInProgress.forEach((flow) => {
|
flowsInProgress.forEach((flow) => {
|
||||||
// To render title placeholders
|
// To render title placeholders
|
||||||
if (flow.context.title_placeholders) {
|
if (flow.context.title_placeholders) {
|
||||||
|
@ -465,7 +465,8 @@ export const generateLovelaceConfigFromData = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const generateLovelaceConfigFromHass = async (
|
export const generateLovelaceConfigFromHass = async (
|
||||||
hass: HomeAssistant
|
hass: HomeAssistant,
|
||||||
|
localize?: LocalizeFunc
|
||||||
): Promise<LovelaceConfig> => {
|
): Promise<LovelaceConfig> => {
|
||||||
// We want to keep the registry subscriptions alive after generating the UI
|
// We want to keep the registry subscriptions alive after generating the UI
|
||||||
// so that we don't serve up stale data after changing areas.
|
// so that we don't serve up stale data after changing areas.
|
||||||
@ -488,6 +489,6 @@ export const generateLovelaceConfigFromHass = async (
|
|||||||
deviceEntries,
|
deviceEntries,
|
||||||
entityEntries,
|
entityEntries,
|
||||||
hass.states,
|
hass.states,
|
||||||
hass.localize
|
localize || hass.localize
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -288,7 +288,8 @@ class LovelacePanel extends LitElement {
|
|||||||
this._errorMsg = err.message;
|
this._errorMsg = err.message;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
conf = await generateLovelaceConfigFromHass(this.hass!);
|
const localize = await this.hass!.loadBackendTranslation("title");
|
||||||
|
conf = await generateLovelaceConfigFromHass(this.hass!, localize);
|
||||||
confMode = "generated";
|
confMode = "generated";
|
||||||
} finally {
|
} finally {
|
||||||
// Ignore updates for another 2 seconds.
|
// Ignore updates for another 2 seconds.
|
||||||
@ -370,8 +371,9 @@ class LovelacePanel extends LitElement {
|
|||||||
const { config: previousConfig, mode: previousMode } = this.lovelace!;
|
const { config: previousConfig, mode: previousMode } = this.lovelace!;
|
||||||
try {
|
try {
|
||||||
// Optimistic update
|
// Optimistic update
|
||||||
|
const localize = await this.hass!.loadBackendTranslation("title");
|
||||||
this._updateLovelace({
|
this._updateLovelace({
|
||||||
config: await generateLovelaceConfigFromHass(this.hass!),
|
config: await generateLovelaceConfigFromHass(this.hass!, localize),
|
||||||
mode: "generated",
|
mode: "generated",
|
||||||
editMode: false,
|
editMode: false,
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { atLeastVersion } from "../common/config/version";
|
import { atLeastVersion } from "../common/config/version";
|
||||||
import { computeLocalize } from "../common/translations/localize";
|
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
import { computeRTL } from "../common/util/compute_rtl";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
import {
|
import {
|
||||||
@ -104,29 +104,37 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
this._loadFragmentTranslations(hass.language, hass.panelUrl);
|
this._loadFragmentTranslations(hass.language, hass.panelUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load translations from the backend
|
||||||
|
* @param language language to fetch
|
||||||
|
* @param category category to fetch
|
||||||
|
* @param integration optional, if having to fetch for specific integration
|
||||||
|
* @param configFlow optional, if having to fetch for all integrations with a config flow
|
||||||
|
* @param force optional, load even if already cached
|
||||||
|
*/
|
||||||
private async _loadHassTranslations(
|
private async _loadHassTranslations(
|
||||||
language: string,
|
language: string,
|
||||||
category: Parameters<typeof getHassTranslations>[2],
|
category: Parameters<typeof getHassTranslations>[2],
|
||||||
integration?: Parameters<typeof getHassTranslations>[3],
|
integration?: Parameters<typeof getHassTranslations>[3],
|
||||||
configFlow?: Parameters<typeof getHassTranslations>[4],
|
configFlow?: Parameters<typeof getHassTranslations>[4],
|
||||||
force = false
|
force = false
|
||||||
) {
|
): Promise<LocalizeFunc> {
|
||||||
if (
|
if (
|
||||||
__BACKWARDS_COMPAT__ &&
|
__BACKWARDS_COMPAT__ &&
|
||||||
!atLeastVersion(this.hass!.connection.haVersion, 0, 109)
|
!atLeastVersion(this.hass!.connection.haVersion, 0, 109)
|
||||||
) {
|
) {
|
||||||
if (category !== "state") {
|
if (category !== "state") {
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
const resources = await getHassTranslationsPre109(this.hass!, language);
|
const resources = await getHassTranslationsPre109(this.hass!, language);
|
||||||
|
|
||||||
// Ignore the repsonse if user switched languages before we got response
|
// Ignore the repsonse if user switched languages before we got response
|
||||||
if (this.hass!.language !== language) {
|
if (this.hass!.language !== language) {
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateResources(language, resources);
|
this._updateResources(language, resources);
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
|
|
||||||
let alreadyLoaded: LoadedTranslationCategory;
|
let alreadyLoaded: LoadedTranslationCategory;
|
||||||
@ -145,12 +153,12 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
if (!force) {
|
if (!force) {
|
||||||
if (integration) {
|
if (integration) {
|
||||||
if (alreadyLoaded.integrations.includes(integration)) {
|
if (alreadyLoaded.integrations.includes(integration)) {
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
configFlow ? alreadyLoaded.configFlow : alreadyLoaded.setup
|
configFlow ? alreadyLoaded.configFlow : alreadyLoaded.setup
|
||||||
) {
|
) {
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,10 +184,11 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
|
|
||||||
// Ignore the repsonse if user switched languages before we got response
|
// Ignore the repsonse if user switched languages before we got response
|
||||||
if (this.hass!.language !== language) {
|
if (this.hass!.language !== language) {
|
||||||
return;
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateResources(language, resources);
|
this._updateResources(language, resources);
|
||||||
|
return this.hass!.localize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadFragmentTranslations(
|
private async _loadFragmentTranslations(
|
||||||
@ -214,9 +223,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
// multiple fragments.
|
// multiple fragments.
|
||||||
const resources = {
|
const resources = {
|
||||||
[language]: {
|
[language]: {
|
||||||
...(this.hass &&
|
...this.hass?.resources?.[language],
|
||||||
this.hass.resources &&
|
|
||||||
this.hass.resources[language]),
|
|
||||||
...data,
|
...data,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -224,7 +224,7 @@ export interface HomeAssistant {
|
|||||||
category: Parameters<typeof getHassTranslations>[2],
|
category: Parameters<typeof getHassTranslations>[2],
|
||||||
integration?: Parameters<typeof getHassTranslations>[3],
|
integration?: Parameters<typeof getHassTranslations>[3],
|
||||||
configFlow?: Parameters<typeof getHassTranslations>[4]
|
configFlow?: Parameters<typeof getHassTranslations>[4]
|
||||||
): Promise<void>;
|
): Promise<LocalizeFunc>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LightEntity = HassEntityBase & {
|
export type LightEntity = HassEntityBase & {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user