refactor: consolidate English translations (#6640)

This commit is contained in:
Thomas authored and GitHub committed 2026-08-21 19:00:27 +02:00
1 parent 81aa704537
commit 9e14a07e64
449 files changed
+3515 -3922

No files matched your search

@@ -10,8 +10,9 @@ describe("DynamicBreadcrumb", () => {
// Dynamic ids (e.g. /manage/custom-widgets/workshop/<id>) have no message and are
// not mapped while their page loads; resolving them must not raise MISSING_MESSAGE.
expect(source).toContain("let label = pathnamePart");
expect(source).toContain("if (mappedValue !== undefined)");
expect(source).toContain("t.has(labelKey)");
expect(source).toContain("mappedValue ?? (t.has(labelKey) ? t(labelKey) : pathnamePart)");
expect(source).not.toMatch(/\{t\(`\$\{translationKey\}\.label`/u);
});
});
@@ -5,7 +5,7 @@ import { Anchor, Badge, Breadcrumbs, Text } from "@mantine/core";
import { IconHomeFilled } from "@tabler/icons-react";
import type { TranslationKeys } from "@homarr/translation";
import { useScopedI18n } from "@homarr/translation/client";
import { useI18n } from "@homarr/translation/client";
interface DynamicBreadcrumbProps {
customHome?: string | null;
@@ -15,6 +15,52 @@ interface DynamicBreadcrumbProps {
}
const categorySegments = new Set(["tools"]);
const commonActionLabels: Record<string, "create" | "edit"> = {
"manage.integrations.edit": "edit",
"manage.search-engines.edit": "edit",
"manage.apps.edit": "edit",
"manage.custom-widgets.edit": "edit",
"manage.users.create": "create",
};
const commonLabelLabels: Record<string, "new"> = {
"manage.integrations.new": "new",
"manage.search-engines.new": "new",
"manage.apps.new": "new",
"manage.custom-widgets.new": "new",
};
const commonEntityLabels: Record<
string,
| "apps"
| "boards"
| "certificates"
| "customWidgets"
| "groups"
| "integrations"
| "invites"
| "logs"
| "media"
| "searchEngines"
| "tasks"
| "users"
> = {
"manage.boards": "boards",
"manage.integrations": "integrations",
"manage.apps": "apps",
"manage.custom-widgets": "customWidgets",
"manage.medias": "media",
"manage.search-engines": "searchEngines",
"manage.users": "users",
"manage.users.groups": "groups",
"manage.users.invites": "invites",
"manage.tools.certificates": "certificates",
"manage.tools.docker.logs": "logs",
"manage.tools.logs": "logs",
"manage.tools.tasks": "tasks",
};
const invariantLabels: Record<string, "Docker" | "Kubernetes"> = {
"manage.tools.docker": "Docker",
"manage.tools.kubernetes": "Kubernetes",
};
/**
* Breadcrumb is client side rendered. Elements are automatically
@@ -32,8 +78,11 @@ export const DynamicBreadcrumb = ({
}: DynamicBreadcrumbProps) => {
const pathname = usePathname();
const pathnameParts = pathname.split("/").filter((part) => part.length > 0);
const t = useScopedI18n("navigationStructure");
const tNavbar = useScopedI18n("management.navbar.items");
const t = useI18n("navigationStructure");
const tNavbar = useI18n("management.navbar.items");
const tCommonAction = useI18n("common.action");
const tCommonEntity = useI18n("common.entity");
const tCommonLabel = useI18n("common.label");
const length = pathnameParts.filter((part) => part !== customHome).length;
@@ -69,7 +118,24 @@ export const DynamicBreadcrumb = ({
// their page is still loading. Fall back to the raw segment instead of
// raising MISSING_MESSAGE.
const labelKey = `${translationKey}.label` as TranslationKeys;
const label = mappedValue ?? (t.has(labelKey) ? t(labelKey) : pathnamePart);
const commonActionKey = commonActionLabels[translationKey];
const commonLabelKey = commonLabelLabels[translationKey];
const commonEntityKey = commonEntityLabels[translationKey];
const invariantLabel = invariantLabels[translationKey];
let label = pathnamePart;
if (mappedValue !== undefined) {
label = mappedValue;
} else if (commonActionKey) {
label = tCommonAction(commonActionKey);
} else if (commonLabelKey) {
label = tCommonLabel(commonLabelKey);
} else if (commonEntityKey) {
label = tCommonEntity(commonEntityKey);
} else if (invariantLabel) {
label = invariantLabel;
} else if (t.has(labelKey)) {
label = t(labelKey);
}
if (isNonInteractable) {
return <Text key={href}>{label}</Text>;