feat: 增加管理端多语言与多模块界面国际化支持
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Breadcrumb,
|
||||
BreadcrumbItem,
|
||||
@@ -11,13 +12,12 @@ import {
|
||||
BreadcrumbSeparator,
|
||||
} from "@/components/ui/breadcrumb";
|
||||
import { adminShellNavItems, ADMIN_BASE } from "@/modules/_config/admin-nav";
|
||||
import { CONFIG_ROUTE_LABELS } from "@/modules/config/config-nav-model";
|
||||
import React from "react";
|
||||
|
||||
const DRAW_ROUTE_LABELS: Record<string, string> = {
|
||||
finance: "期号收支",
|
||||
review: "审核",
|
||||
results: "开奖结果",
|
||||
finance: "Draw Finance",
|
||||
review: "Review",
|
||||
results: "Results",
|
||||
};
|
||||
|
||||
function titleCase(value: string): string {
|
||||
@@ -34,15 +34,16 @@ type BreadcrumbCrumb = {
|
||||
};
|
||||
|
||||
export function AdminBreadcrumb() {
|
||||
const { t } = useTranslation(["common", "dashboard", "reports", "audit", "config", "draws"]);
|
||||
const pathname = usePathname();
|
||||
|
||||
// 把路径拆分成段
|
||||
// Split the current path into segments.
|
||||
const segments = pathname.split("/").filter(Boolean);
|
||||
|
||||
// 基础面包屑:首页/仪表盘
|
||||
// Base breadcrumb: home / dashboard.
|
||||
const breadcrumbs: BreadcrumbCrumb[] = [
|
||||
{
|
||||
label: "首页",
|
||||
label: t("nav.home", { ns: "common" }),
|
||||
href: ADMIN_BASE,
|
||||
isCurrent: pathname === ADMIN_BASE,
|
||||
},
|
||||
@@ -56,8 +57,16 @@ export function AdminBreadcrumb() {
|
||||
});
|
||||
|
||||
if (navItem && navItem.href !== ADMIN_BASE) {
|
||||
const navLabelMap: Record<string, string> = {
|
||||
dashboard: t("title", { ns: "dashboard" }),
|
||||
reports: t("title", { ns: "reports" }),
|
||||
"audit-logs": t("title", { ns: "audit" }),
|
||||
};
|
||||
breadcrumbs.push({
|
||||
label: navItem.segment === "draws" ? "期号列表" : navItem.label,
|
||||
label:
|
||||
navItem.segment === "draws"
|
||||
? "Draws"
|
||||
: navLabelMap[navItem.segment] ?? navItem.label,
|
||||
href: navItem.href,
|
||||
isCurrent: pathname === navItem.href || segments.length === 2,
|
||||
});
|
||||
@@ -67,9 +76,14 @@ export function AdminBreadcrumb() {
|
||||
const subSegment = segments[2];
|
||||
let subLabel = "";
|
||||
if (businessSegment === "config" && subSegment) {
|
||||
subLabel = CONFIG_ROUTE_LABELS[subSegment] ?? titleCase(subSegment);
|
||||
subLabel = t(`nav.items.${subSegment}`, { ns: "config", defaultValue: titleCase(subSegment) });
|
||||
} else {
|
||||
subLabel = subSegment ? DRAW_ROUTE_LABELS[subSegment] ?? titleCase(subSegment) : "";
|
||||
subLabel = subSegment
|
||||
? t(`subnav.${subSegment}`, {
|
||||
ns: "draws",
|
||||
defaultValue: DRAW_ROUTE_LABELS[subSegment] ?? titleCase(subSegment),
|
||||
})
|
||||
: "";
|
||||
}
|
||||
if (subLabel) {
|
||||
breadcrumbs.push({
|
||||
|
||||
Reference in New Issue
Block a user