Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getHassTranslations = async (
hass: HomeAssistant,
language: string,
category: TranslationCategory,
integration?: string,
integration?: string | string[],
config_flow?: boolean
): Promise<Record<string, unknown>> => {
const result = await hass.callWS<{ resources: Record<string, unknown> }>({
Expand Down
4 changes: 3 additions & 1 deletion src/onboarding/onboarding-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class OnboardingIntegrations extends LitElement {
this.hass.loadBackendTranslation("title", undefined, true);
this._unsubEvents = subscribeConfigFlowInProgress(this.hass, (flows) => {
this._discovered = flows;
const integrations: Set<string> = new Set();
for (const flow of flows) {
// To render title placeholders
if (flow.context.title_placeholders) {
this.hass.loadBackendTranslation("config", flow.handler);
integrations.add(flow.handler);
}
}
this.hass.loadBackendTranslation("config", Array.from(integrations));
});
}

Expand Down
11 changes: 6 additions & 5 deletions src/panels/config/integrations/ha-config-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,18 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
this._deviceRegistryEntries = entries;
}),
subscribeConfigFlowInProgress(this.hass, async (flowsInProgress) => {
const translationsPromisses: Promise<LocalizeFunc>[] = [];
const integrations: Set<string> = new Set();
flowsInProgress.forEach((flow) => {
// To render title placeholders
if (flow.context.title_placeholders) {
translationsPromisses.push(
this.hass.loadBackendTranslation("config", flow.handler)
);
integrations.add(flow.handler);
}
this._fetchManifest(flow.handler);
});
await Promise.all(translationsPromisses);
await this.hass.loadBackendTranslation(
"config",
Array.from(integrations)
);
await nextRender();
this._configEntriesInProgress = flowsInProgress.map((flow) => ({
...flow,
Expand Down
20 changes: 14 additions & 6 deletions src/state/translations-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,22 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
};
}

let integrationsToLoad: string[] = [];

// Check if already loaded
if (!force) {
if (integration) {
if (integration && Array.isArray(integration)) {
integrationsToLoad = integration.filter(
(i) => !alreadyLoaded.integrations.includes(i)
);
if (!integrationsToLoad.length) {
return this.hass!.localize;
}
} else if (integration) {
if (alreadyLoaded.integrations.includes(integration)) {
return this.hass!.localize;
}
integrationsToLoad = [integration];
} else if (
configFlow ? alreadyLoaded.configFlow : alreadyLoaded.setup
) {
Expand All @@ -253,10 +263,8 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
}

// Add to cache
if (integration) {
if (!alreadyLoaded.integrations.includes(integration)) {
alreadyLoaded.integrations.push(integration);
}
if (integrationsToLoad.length) {
alreadyLoaded.integrations.push(...integrationsToLoad);
} else {
alreadyLoaded.setup = true;
if (configFlow) {
Expand All @@ -268,7 +276,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
this.hass!,
language,
category,
integration,
integrationsToLoad.length ? integrationsToLoad : undefined,
configFlow
);

Expand Down