mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix integration translations (#16678)
This commit is contained in:
parent
88522ed155
commit
eb0759a3b3
@ -1,6 +1,7 @@
|
||||
import { PropertyValues } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||
import {
|
||||
ConfigEntry,
|
||||
subscribeConfigEntries,
|
||||
@ -74,14 +75,20 @@ class HaConfigIntegrations extends SubscribeMixin(HassRouterPage) {
|
||||
@property()
|
||||
private _configEntriesInProgress?: DataEntryFlowProgressExtended[];
|
||||
|
||||
private _loadTranslationsPromise?: Promise<unknown>;
|
||||
private _loadTranslationsPromise?: Promise<LocalizeFunc>;
|
||||
|
||||
public hassSubscribe() {
|
||||
return [
|
||||
subscribeConfigEntries(
|
||||
this.hass,
|
||||
async (messages) => {
|
||||
await this._loadTranslationsPromise;
|
||||
await this._loadTranslationsPromise?.then(
|
||||
() =>
|
||||
// allow hass to update
|
||||
new Promise((resolve) => {
|
||||
window.setTimeout(resolve, 0);
|
||||
})
|
||||
);
|
||||
let fullUpdate = false;
|
||||
const newEntries: ConfigEntryExtended[] = [];
|
||||
messages.forEach((message) => {
|
||||
@ -140,13 +147,12 @@ class HaConfigIntegrations extends SubscribeMixin(HassRouterPage) {
|
||||
];
|
||||
}
|
||||
|
||||
protected firstUpdated(changed: PropertyValues) {
|
||||
super.firstUpdated(changed);
|
||||
this._loadTranslationsPromise = this.hass.loadBackendTranslation(
|
||||
"title",
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
protected willUpdate(changed: PropertyValues) {
|
||||
super.willUpdate(changed);
|
||||
if (this.hasUpdated) {
|
||||
return;
|
||||
}
|
||||
this._loadTranslationsPromise = this.hass.loadBackendTranslation("title");
|
||||
}
|
||||
|
||||
protected updatePageEl(pageEl) {
|
||||
|
@ -278,8 +278,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
return this.hass!.localize;
|
||||
}
|
||||
|
||||
await this._updateResources(language, resources);
|
||||
return this.hass!.localize;
|
||||
return this._updateResources(language, resources);
|
||||
}
|
||||
|
||||
let alreadyLoaded: LoadedTranslationCategory;
|
||||
@ -340,8 +339,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
return this.hass!.localize;
|
||||
}
|
||||
|
||||
await this._updateResources(language, resources);
|
||||
return this.hass!.localize;
|
||||
return this._updateResources(language, resources);
|
||||
}
|
||||
|
||||
private async _loadFragmentTranslations(
|
||||
@ -370,8 +368,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
}
|
||||
this.__loadedFragmetTranslations.add(fragment);
|
||||
const result = await getTranslation(fragment, language);
|
||||
await this._updateResources(result.language, result.data);
|
||||
return this.hass!.localize;
|
||||
return this._updateResources(result.language, result.data);
|
||||
}
|
||||
|
||||
private async _loadCoreTranslations(language: string) {
|
||||
@ -389,7 +386,10 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
}
|
||||
}
|
||||
|
||||
private async _updateResources(language: string, data: any) {
|
||||
private async _updateResources(
|
||||
language: string,
|
||||
data: any
|
||||
): Promise<LocalizeFunc> {
|
||||
updateResourcesIteration++;
|
||||
const i = updateResourcesIteration;
|
||||
|
||||
@ -410,7 +410,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
|
||||
if (language !== (this.hass ?? this._pendingHass).language) {
|
||||
// the language was changed, abort
|
||||
return;
|
||||
return (this.hass ?? this._pendingHass).localize!;
|
||||
}
|
||||
|
||||
const resources = {
|
||||
@ -430,13 +430,15 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
language !== (this.hass ?? this._pendingHass).language
|
||||
) {
|
||||
// if a new iteration has started or the language changed, abort
|
||||
return;
|
||||
return localize;
|
||||
}
|
||||
|
||||
this._updateHass({
|
||||
localize,
|
||||
});
|
||||
fireEvent(this, "translations-updated");
|
||||
|
||||
return localize;
|
||||
}
|
||||
|
||||
private _refetchCachedHassTranslations(
|
||||
|
Loading…
x
Reference in New Issue
Block a user