refactor: consolidate English translations (#6640)
This commit is contained in:
1 parent
81aa704537
commit
9e14a07e64
449 files changed
+3515
-3922
No files matched your search
@@ -5,7 +5,7 @@ import { clientApi } from "@homarr/api/client";
|
||||
import { AppForm } from "@homarr/forms-collection";
|
||||
import { createModal, modalSizeForm } from "@homarr/modals";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import type { appManageSchema } from "@homarr/validation/app";
|
||||
|
||||
interface QuickAddAppModalProps {
|
||||
@@ -13,13 +13,14 @@ interface QuickAddAppModalProps {
|
||||
}
|
||||
|
||||
export const QuickAddAppModal = createModal<QuickAddAppModalProps>(({ actions, innerProps }) => {
|
||||
const tScoped = useScopedI18n("app.page.create.notification");
|
||||
const t = useI18n();
|
||||
const tScoped = useI18n("app.page.create.notification");
|
||||
const tCommon = useI18n("common");
|
||||
const tBoard = useI18n("board");
|
||||
|
||||
const { mutate, isPending } = clientApi.app.create.useMutation({
|
||||
onError: () => {
|
||||
showErrorNotification({
|
||||
title: tScoped("error.title"),
|
||||
title: tCommon("notification.create.error"),
|
||||
message: tScoped("error.message"),
|
||||
});
|
||||
},
|
||||
@@ -29,7 +30,7 @@ export const QuickAddAppModal = createModal<QuickAddAppModalProps>(({ actions, i
|
||||
mutate(values, {
|
||||
onSuccess(app) {
|
||||
showSuccessNotification({
|
||||
title: tScoped("success.title"),
|
||||
title: tCommon("notification.create.success"),
|
||||
message: tScoped("success.message"),
|
||||
});
|
||||
|
||||
@@ -42,7 +43,7 @@ export const QuickAddAppModal = createModal<QuickAddAppModalProps>(({ actions, i
|
||||
return (
|
||||
<AppForm
|
||||
buttonLabels={{
|
||||
submit: t("board.action.quickCreateApp.modal.createAndUse"),
|
||||
submit: tBoard("action.quickCreateApp.modal.createAndUse"),
|
||||
submitAndCreateAnother: undefined,
|
||||
}}
|
||||
showBackToOverview={false}
|
||||
|
||||
@@ -12,7 +12,8 @@ import { useI18n } from "@homarr/translation/client";
|
||||
import { boardColumnCountSchema, boardCreateSchema, boardNameSchema } from "@homarr/validation/board";
|
||||
|
||||
export const AddBoardModal = createModal(({ actions }) => {
|
||||
const t = useI18n();
|
||||
const tBoard = useI18n("board");
|
||||
const tCommon = useI18n("common");
|
||||
const router = useRouter();
|
||||
const form = useZodForm(boardCreateSchema, {
|
||||
mode: "controlled",
|
||||
@@ -39,8 +40,8 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
onSuccess: (result) => {
|
||||
actions.closeModal();
|
||||
showSuccessNotification({
|
||||
title: t("board.action.create.notification.success.title"),
|
||||
message: t("board.action.create.notification.success.message", { name: values.name }),
|
||||
title: tBoard("action.create.notification.success.title"),
|
||||
message: tBoard("action.create.notification.success.message", { name: values.name }),
|
||||
});
|
||||
const name = encodeURIComponent(result.name);
|
||||
const layoutId = encodeURIComponent(result.layoutId);
|
||||
@@ -48,8 +49,8 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
},
|
||||
onError() {
|
||||
showErrorNotification({
|
||||
title: t("board.action.create.notification.error.title"),
|
||||
message: t("board.action.create.notification.error.message", { name: values.name }),
|
||||
title: tBoard("action.create.notification.error.title"),
|
||||
message: tBoard("action.create.notification.error.message", { name: values.name }),
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -57,7 +58,7 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
>
|
||||
<Stack>
|
||||
<TextInput
|
||||
label={t("board.field.name.label")}
|
||||
label={tCommon("field.name")}
|
||||
data-autofocus
|
||||
{...form.getInputProps("name")}
|
||||
description={
|
||||
@@ -71,7 +72,7 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
<InputWrapper label={t("board.field.columnCount.label")} {...form.getInputProps("columnCount")}>
|
||||
<InputWrapper label={tBoard("field.columnCount.label")} {...form.getInputProps("columnCount")}>
|
||||
<Slider
|
||||
min={boardColumnCountSchema.minValue ?? undefined}
|
||||
max={boardColumnCountSchema.maxValue ?? undefined}
|
||||
@@ -81,17 +82,17 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
</InputWrapper>
|
||||
|
||||
<Switch
|
||||
label={t("board.field.isPublic.label")}
|
||||
description={t("board.field.isPublic.description")}
|
||||
label={tBoard("field.isPublic.label")}
|
||||
description={tBoard("field.isPublic.description")}
|
||||
{...form.getInputProps("isPublic")}
|
||||
/>
|
||||
|
||||
<Group justify="right">
|
||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||
{t("common.action.cancel")}
|
||||
{tCommon("action.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" loading={isPending}>
|
||||
{t("common.action.create")}
|
||||
{tCommon("action.create")}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
@@ -102,7 +103,8 @@ export const AddBoardModal = createModal(({ actions }) => {
|
||||
});
|
||||
|
||||
export const useBoardNameStatus = (name: string) => {
|
||||
const t = useI18n();
|
||||
const tBoard = useI18n("board");
|
||||
const tCommon = useI18n("common");
|
||||
const [debouncedName] = useDebouncedValue(name, 250);
|
||||
const { data: boardExists, isLoading } = clientApi.board.exists.useQuery(debouncedName, {
|
||||
enabled: boardNameSchema.safeParse(debouncedName).success,
|
||||
@@ -115,19 +117,19 @@ export const useBoardNameStatus = (name: string) => {
|
||||
? undefined
|
||||
: isLoading
|
||||
? {
|
||||
label: t("board.action.create.availability.checking"),
|
||||
label: tBoard("action.create.availability.checking"),
|
||||
}
|
||||
: boardExists === undefined
|
||||
? undefined
|
||||
: boardExists
|
||||
? {
|
||||
icon: IconAlertTriangle,
|
||||
label: t("common.zod.errors.custom.boardAlreadyExists"), // The board ${debouncedName} already exists
|
||||
label: tCommon("zod.errors.custom.boardAlreadyExists"), // The board ${debouncedName} already exists
|
||||
color: "red",
|
||||
}
|
||||
: {
|
||||
icon: IconCircleCheck,
|
||||
label: t("board.action.create.availability.available", { name: debouncedName }),
|
||||
label: tBoard("action.create.availability.available", { name: debouncedName }),
|
||||
color: "green",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@ interface InnerProps {
|
||||
}
|
||||
|
||||
export const DuplicateBoardModal = createModal<InnerProps>(({ actions, innerProps }) => {
|
||||
const t = useI18n();
|
||||
const tBoard = useI18n("board");
|
||||
const tCommon = useI18n("common");
|
||||
const form = useZodForm(boardDuplicateSchema.omit({ id: true }), {
|
||||
mode: "controlled",
|
||||
initialValues: {
|
||||
@@ -46,14 +47,14 @@ export const DuplicateBoardModal = createModal<InnerProps>(({ actions, innerProp
|
||||
onSuccess() {
|
||||
actions.closeModal();
|
||||
showSuccessNotification({
|
||||
title: t("board.action.duplicate.notification.success.title"),
|
||||
message: t("board.action.duplicate.notification.success.message"),
|
||||
title: tBoard("action.duplicate.notification.success.title"),
|
||||
message: tBoard("action.duplicate.notification.success.message"),
|
||||
});
|
||||
},
|
||||
onError() {
|
||||
showErrorNotification({
|
||||
title: t("board.action.duplicate.notification.error.title"),
|
||||
message: t("board.action.duplicate.notification.error.message"),
|
||||
title: tBoard("action.duplicate.notification.error.title"),
|
||||
message: tBoard("action.duplicate.notification.error.message"),
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -62,11 +63,11 @@ export const DuplicateBoardModal = createModal<InnerProps>(({ actions, innerProp
|
||||
>
|
||||
<Stack>
|
||||
<Text size="sm" c="gray.6">
|
||||
{t("board.action.duplicate.message", { name: innerProps.board.name })}
|
||||
{tBoard("action.duplicate.message", { name: innerProps.board.name })}
|
||||
</Text>
|
||||
|
||||
<TextInput
|
||||
label={t("board.field.name.label")}
|
||||
label={tCommon("field.name")}
|
||||
data-autofocus
|
||||
{...form.getInputProps("name")}
|
||||
description={
|
||||
@@ -82,10 +83,10 @@ export const DuplicateBoardModal = createModal<InnerProps>(({ actions, innerProp
|
||||
|
||||
<Group justify="end">
|
||||
<Button variant="subtle" color="gray" onClick={actions.closeModal}>
|
||||
{t("common.action.cancel")}
|
||||
{tCommon("action.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" loading={isPending}>
|
||||
{t("common.action.create")}
|
||||
{tCommon("action.create")}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -7,11 +7,17 @@ describe("createDockerRemovalConfirmation", () => {
|
||||
const remove = vi.fn();
|
||||
const t = vi.fn((key: string, values?: Record<string, string>) => `${key}:${JSON.stringify(values)}`);
|
||||
|
||||
const confirmation = createDockerRemovalConfirmation([{ name: "sonarr" }, { name: "radarr" }], t as never, remove);
|
||||
const confirmation = createDockerRemovalConfirmation(
|
||||
[{ name: "sonarr" }, { name: "radarr" }],
|
||||
t as never,
|
||||
"Remove",
|
||||
remove,
|
||||
);
|
||||
|
||||
expect(remove).not.toHaveBeenCalled();
|
||||
expect(confirmation.title).toContain('"count":"2"');
|
||||
expect(confirmation.children).toContain('"names":"sonarr, radarr"');
|
||||
expect(confirmation.confirmProps.children).toBe("Remove");
|
||||
|
||||
confirmation.onConfirm();
|
||||
expect(remove).toHaveBeenCalledOnce();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { useConfirmModal } from "@homarr/modals";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
interface DockerContainerName {
|
||||
name: string;
|
||||
@@ -11,7 +11,8 @@ interface DockerContainerName {
|
||||
|
||||
export const createDockerRemovalConfirmation = (
|
||||
containers: DockerContainerName[],
|
||||
t: ReturnType<typeof useScopedI18n<"docker.action.remove">>,
|
||||
t: ReturnType<typeof useI18n<"docker.action.remove">>,
|
||||
confirmLabel: string,
|
||||
onConfirm: () => void | Promise<void>,
|
||||
) => ({
|
||||
title: t("confirmation.title", { count: String(containers.length) }),
|
||||
@@ -19,18 +20,19 @@ export const createDockerRemovalConfirmation = (
|
||||
count: String(containers.length),
|
||||
names: containers.map(({ name }) => name).join(", "),
|
||||
}),
|
||||
confirmProps: { children: t("label"), color: "red.9" },
|
||||
confirmProps: { children: confirmLabel, color: "red.9" },
|
||||
onConfirm,
|
||||
});
|
||||
|
||||
export const useDockerContainerRemovalConfirmation = () => {
|
||||
const t = useScopedI18n("docker.action.remove");
|
||||
const t = useI18n("docker.action.remove");
|
||||
const commonT = useI18n("common.action");
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
|
||||
return useCallback(
|
||||
(containers: DockerContainerName[], onConfirm: () => void | Promise<void>) => {
|
||||
openConfirmModal(createDockerRemovalConfirmation(containers, t, onConfirm));
|
||||
openConfirmModal(createDockerRemovalConfirmation(containers, t, commonT("remove"), onConfirm));
|
||||
},
|
||||
[openConfirmModal, t],
|
||||
[commonT, openConfirmModal, t],
|
||||
);
|
||||
};
|
||||
@@ -9,7 +9,8 @@ import { useI18n } from "@homarr/translation/client";
|
||||
import { groupCreateSchema } from "@homarr/validation/group";
|
||||
|
||||
export const AddGroupModal = createModal<void>(({ actions }) => {
|
||||
const t = useI18n();
|
||||
const tGroup = useI18n("group");
|
||||
const tCommon = useI18n("common");
|
||||
const { mutate, isPending } = clientApi.group.createGroup.useMutation();
|
||||
const form = useZodForm(groupCreateSchema, {
|
||||
initialValues: {
|
||||
@@ -25,27 +26,27 @@ export const AddGroupModal = createModal<void>(({ actions }) => {
|
||||
actions.closeModal();
|
||||
void revalidatePathActionAsync("/manage/users/groups");
|
||||
showSuccessNotification({
|
||||
title: t("common.notification.create.success"),
|
||||
message: t("group.action.create.notification.success.message"),
|
||||
title: tCommon("notification.create.success"),
|
||||
message: tGroup("action.create.notification.success.message"),
|
||||
});
|
||||
},
|
||||
onError() {
|
||||
showErrorNotification({
|
||||
title: t("common.notification.create.error"),
|
||||
message: t("group.action.create.notification.error.message"),
|
||||
title: tCommon("notification.create.error"),
|
||||
message: tGroup("action.create.notification.error.message"),
|
||||
});
|
||||
},
|
||||
});
|
||||
})}
|
||||
>
|
||||
<Stack>
|
||||
<TextInput label={t("group.field.name")} data-autofocus {...form.getInputProps("name")} />
|
||||
<TextInput label={tCommon("field.name")} data-autofocus {...form.getInputProps("name")} />
|
||||
<Group justify="right">
|
||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||
{t("common.action.cancel")}
|
||||
{tCommon("action.cancel")}
|
||||
</Button>
|
||||
<Button loading={isPending} type="submit">
|
||||
{t("common.action.create")}
|
||||
{tCommon("action.create")}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -2,12 +2,13 @@ import { usePathname } from "next/navigation";
|
||||
import { Button, CopyButton, Mark, Stack, Text } from "@mantine/core";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { invariantTechnicalLabels } from "@homarr/definitions";
|
||||
import { createModal } from "@homarr/modals";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { Link } from "@homarr/ui";
|
||||
|
||||
export const InviteCopyModal = createModal<RouterOutputs["invite"]["createInvite"]>(({ actions, innerProps }) => {
|
||||
const t = useScopedI18n("management.page.user.invite");
|
||||
const t = useI18n("management.page.user.invite");
|
||||
const inviteUrl = useInviteUrl(innerProps);
|
||||
|
||||
return (
|
||||
@@ -19,7 +20,7 @@ export const InviteCopyModal = createModal<RouterOutputs["invite"]["createInvite
|
||||
</Text>
|
||||
<Link href={createPath(innerProps)}>{t("action.copy.link")}</Link>
|
||||
<Stack gap="xs">
|
||||
<Text fw="bold">{t("field.id.label")}:</Text>
|
||||
<Text fw="bold">{invariantTechnicalLabels.id}:</Text>
|
||||
<Mark style={{ borderRadius: 4 }} color="gray" px={5}>
|
||||
{innerProps.id}
|
||||
</Mark>
|
||||
|
||||
@@ -6,7 +6,7 @@ import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useForm } from "@homarr/form";
|
||||
import { createModal, useModalAction } from "@homarr/modals";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import { InviteCopyModal } from "./invite-copy-modal";
|
||||
|
||||
@@ -17,7 +17,7 @@ interface FormType {
|
||||
}
|
||||
|
||||
export const InviteCreateModal = createModal<void>(({ actions }) => {
|
||||
const tInvite = useScopedI18n("management.page.user.invite");
|
||||
const tInvite = useI18n("management.page.user.invite");
|
||||
const t = useI18n();
|
||||
const { openModal } = useModalAction(InviteCopyModal);
|
||||
|
||||
|
||||
Reference in new issue
Block a user