added some initial work on intl
This commit is contained in:
1 parent
157efa04b1
commit
caad458b48
22 files changed
+588
-155
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { LangStore, useLang } from "lang";
|
||||
import { useEffect, useState } from "react";
|
||||
import { AutomationData, BareAutomationData } from "types/automations";
|
||||
import { defaultAutomation } from "utils/defaults";
|
||||
@@ -10,7 +11,8 @@ export const useAutomationDB = (
|
||||
configAutomations: AutomationData[],
|
||||
tagsDB: TagDB
|
||||
) => {
|
||||
const autoMap = genMapping(haEntities, configAutomations, tagsDB);
|
||||
const langStore = useLang();
|
||||
const autoMap = genMapping(haEntities, configAutomations, tagsDB, langStore);
|
||||
const [newAuto, setNewAuto] =
|
||||
useState<
|
||||
null | [AutomationManagerAuto, AutomationData | BareAutomationData]
|
||||
@@ -54,13 +56,13 @@ export const useAutomationDB = (
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
state: langStore.get("AUTOMATION_STATE_UNREGISTERED"),
|
||||
tags: {},
|
||||
issue: "New Automation",
|
||||
issue: langStore.get("NEW_AUTOMATION"),
|
||||
isNew: true,
|
||||
source_file: "n/a",
|
||||
source_file_type: "n/a",
|
||||
configuration_key: ["n/a"],
|
||||
source_file: langStore.get("N/A"),
|
||||
source_file_type: langStore.get("N/A"),
|
||||
configuration_key: [],
|
||||
},
|
||||
auto,
|
||||
]);
|
||||
@@ -72,7 +74,8 @@ export const useAutomationDB = (
|
||||
const genMapping = (
|
||||
haEntities: HassEntities,
|
||||
configAutomations: AutomationData[],
|
||||
tagsDB: TagDB
|
||||
tagsDB: TagDB,
|
||||
langStore: LangStore
|
||||
) => {
|
||||
const configData: Record<string, AutomationData> = configAutomations.reduce(
|
||||
(all, n) => ({
|
||||
@@ -93,7 +96,9 @@ const genMapping = (
|
||||
let description = "";
|
||||
let issue: string | undefined = ["on", "off"].includes(entityData.state)
|
||||
? undefined
|
||||
: `recived invalid state "${entityData.state}, this could be because you have a lingering automation that was not cleared by homeassistant, try to reboot HA or manually clear this automation from HA Database."`;
|
||||
: langStore.get("ISSUES_INVALID_STATE", {
|
||||
state: entityData.state,
|
||||
});
|
||||
let found: AutomationData | null = null;
|
||||
let source_file = "n/a";
|
||||
let source_file_type = "n/a";
|
||||
@@ -107,7 +112,7 @@ const genMapping = (
|
||||
configuration_key = found.configuration_key ?? configuration_key;
|
||||
delete configData[autoId];
|
||||
} else {
|
||||
issue = "failed to find this automation in '/config' folder";
|
||||
issue = langStore.get("ISSUES_FIND_AUTOMATION_IN_CONFIG");
|
||||
}
|
||||
|
||||
automatioinMap[autoId] = [
|
||||
@@ -134,13 +139,12 @@ const genMapping = (
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
state: langStore.get("AUTOMATION_STATE_UNREGISTERED"),
|
||||
tags: tagsDB.getTags(auto.id),
|
||||
source_file: auto.source_file,
|
||||
source_file_type: auto.source_file_type,
|
||||
configuration_key: auto.configuration_key,
|
||||
issue:
|
||||
"homeassistant did not load this automation, try to manually reload automations or restart homeassistant.",
|
||||
issue: langStore.get("ISSUES_NO_LOAD_AUTOMATION"),
|
||||
},
|
||||
auto,
|
||||
];
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "./state";
|
||||
import Alert from "@mui/material/Alert";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
onAutomationDelete: (aid: string, eid: string) => void;
|
||||
@@ -17,13 +18,14 @@ export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
export const AutomationManagerLoaded: FC<
|
||||
PropsWithChildren<AutomationManagerLoadedProps>
|
||||
> = ({ children, ...args }) => {
|
||||
const langStore = useLang();
|
||||
const state = useAutomationManagerState(args);
|
||||
const confirm = useConfirm();
|
||||
|
||||
const onAutomationDelete = async (aid: string, eid: string) =>
|
||||
confirm({
|
||||
title: "Are you sure you want to delete this automation?",
|
||||
confirmationText: "Delete",
|
||||
title: langStore.get("CONFIRMATION_DELETE_THIS_AUTOMATION"),
|
||||
confirmationText: langStore.get("DELETE"),
|
||||
})
|
||||
.then(() => {
|
||||
args.onAutomationDelete(aid, eid);
|
||||
@@ -76,8 +78,9 @@ export const AutomationManagerLoaded: FC<
|
||||
) : (
|
||||
<div>
|
||||
<Alert color="warning">
|
||||
Failed to find an automation on disk with id{" "}
|
||||
{state.currentAutomationId}.
|
||||
{langStore.get("ISSUE_FAILED_TO_FIND_AUTOMATION_ON_DISK", {
|
||||
id: state.currentAutomationId,
|
||||
})}
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useAutomationDB } from "./automationDB";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { AutomationManagerAutoUpdatable } from "../types";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type UseAutomationManagerStateArgs = {
|
||||
configAutomations: AutomationData[];
|
||||
@@ -26,6 +27,7 @@ export const useAutomationManagerState = ({
|
||||
onAutomationStateChange,
|
||||
}: UseAutomationManagerStateArgs) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const cookies = useAMSCookies();
|
||||
@@ -44,10 +46,9 @@ export const useAutomationManagerState = ({
|
||||
const stillHaveNewAreYouSure = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
content:
|
||||
"Selecting another automation will cause you to lose all work done on this new automation. Please save your work on this automation first.",
|
||||
confirmationText: "Switch Automation",
|
||||
cancellationText: "Cancel",
|
||||
content: langStore.get("WARNING_SWITCHING_FROM_NONE_SAVE"),
|
||||
confirmationText: langStore.get("SWITCH_AUTOMATION"),
|
||||
cancellationText: langStore.get("CANCEL"),
|
||||
});
|
||||
return true;
|
||||
} catch (_) {
|
||||
@@ -128,9 +129,10 @@ export const useAutomationManagerState = ({
|
||||
}
|
||||
} else {
|
||||
snackbr.enqueueSnackbar(
|
||||
`Failed to save automation "${aid}" contents - ${JSON.stringify(
|
||||
a
|
||||
)} -- not found in /config`,
|
||||
langStore.get("ERROR_FAILED_TO_SAVE", {
|
||||
aid,
|
||||
contents: JSON.stringify(a),
|
||||
}),
|
||||
{ variant: "error" }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user