mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Restore getHassTranslationsPre109 (#20597)
* Revert "Remove legacy state translations (#20536)" This reverts commit e376efc57920feab37e322f2276beaa31e17d0c0. * keep
This commit is contained in:
parent
469dbbcccc
commit
0725c7b160
@ -97,3 +97,14 @@ export const getHassTranslations = async (
|
||||
});
|
||||
return result.resources;
|
||||
};
|
||||
|
||||
export const getHassTranslationsPre109 = async (
|
||||
hass: HomeAssistant,
|
||||
language: string
|
||||
): Promise<Record<string, unknown>> => {
|
||||
const result = await hass.callWS<{ resources: Record<string, unknown> }>({
|
||||
type: "frontend/get_translations",
|
||||
language,
|
||||
});
|
||||
return result.resources;
|
||||
};
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { atLeastVersion } from "../common/config/version";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
||||
import {
|
||||
@ -8,6 +9,7 @@ import { debounce } from "../common/util/debounce";
|
||||
import {
|
||||
FirstWeekday,
|
||||
getHassTranslations,
|
||||
getHassTranslationsPre109,
|
||||
NumberFormat,
|
||||
saveTranslationPreferences,
|
||||
TimeFormat,
|
||||
@ -284,6 +286,23 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
configFlow?: Parameters<typeof getHassTranslations>[4],
|
||||
force = false
|
||||
): Promise<LocalizeFunc> {
|
||||
if (
|
||||
__BACKWARDS_COMPAT__ &&
|
||||
!atLeastVersion(this.hass!.connection.haVersion, 0, 109)
|
||||
) {
|
||||
if (category !== "state") {
|
||||
return this.hass!.localize;
|
||||
}
|
||||
const resources = await getHassTranslationsPre109(this.hass!, language);
|
||||
|
||||
// Ignore the repsonse if user switched languages before we got response
|
||||
if (this.hass!.language !== language) {
|
||||
return this.hass!.localize;
|
||||
}
|
||||
|
||||
return this._updateResources(language, resources);
|
||||
}
|
||||
|
||||
let alreadyLoaded: LoadedTranslationCategory;
|
||||
|
||||
if (category in this.__loadedTranslations) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user