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