mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 12:46:35 +00:00
Fix translation race condition? (#7885)
This commit is contained in:
parent
3e4955becd
commit
565724d201
@ -210,7 +210,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
this.__coreProgress = language;
|
this.__coreProgress = language;
|
||||||
try {
|
try {
|
||||||
const result = await getTranslation(null, language);
|
const result = await getTranslation(null, language);
|
||||||
this._updateResources(result.language, result.data);
|
await this._updateResources(result.language, result.data);
|
||||||
} finally {
|
} finally {
|
||||||
this.__coreProgress = undefined;
|
this.__coreProgress = undefined;
|
||||||
}
|
}
|
||||||
@ -226,18 +226,26 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
// before this.hass is even created. In this case our base state comes
|
// before this.hass is even created. In this case our base state comes
|
||||||
// from this._pendingHass instead. Otherwise the first set of strings is
|
// from this._pendingHass instead. Otherwise the first set of strings is
|
||||||
// overwritten when we call _updateHass the second time!
|
// overwritten when we call _updateHass the second time!
|
||||||
const baseHass = this.hass ?? this._pendingHass;
|
|
||||||
|
if (language !== (this.hass ?? this._pendingHass).language) {
|
||||||
|
// the language was changed, abort
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const resources = {
|
const resources = {
|
||||||
[language]: {
|
[language]: {
|
||||||
...baseHass?.resources?.[language],
|
...(this.hass ?? this._pendingHass)?.resources?.[language],
|
||||||
...data,
|
...data,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const changes: Partial<HomeAssistant> = { resources };
|
const changes: Partial<HomeAssistant> = {
|
||||||
if (this.hass && language === this.hass.language) {
|
resources,
|
||||||
changes.localize = await computeLocalize(this, language, resources);
|
localize: await computeLocalize(this, language, resources),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (language === (this.hass ?? this._pendingHass).language) {
|
||||||
|
this._updateHass(changes);
|
||||||
}
|
}
|
||||||
this._updateHass(changes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _refetchCachedHassTranslations(
|
private _refetchCachedHassTranslations(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user