refactor: 更新管理端页面元数据,统一国际化支持,移除冗余代码
This commit is contained in:
57
src/lib/page-metadata.ts
Normal file
57
src/lib/page-metadata.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
import enAdminRoles from "@/i18n/locales/en/adminRoles.json";
|
||||
import enAdminUsers from "@/i18n/locales/en/adminUsers.json";
|
||||
import enAudit from "@/i18n/locales/en/audit.json";
|
||||
import enAuth from "@/i18n/locales/en/auth.json";
|
||||
import enConfig from "@/i18n/locales/en/config.json";
|
||||
import enDashboard from "@/i18n/locales/en/dashboard.json";
|
||||
import enDraws from "@/i18n/locales/en/draws.json";
|
||||
import enJackpot from "@/i18n/locales/en/jackpot.json";
|
||||
import enPlayers from "@/i18n/locales/en/players.json";
|
||||
import enReconcile from "@/i18n/locales/en/reconcile.json";
|
||||
import enRisk from "@/i18n/locales/en/risk.json";
|
||||
import enSettlement from "@/i18n/locales/en/settlement.json";
|
||||
import enCommon from "@/i18n/locales/en/common.json";
|
||||
import enTickets from "@/i18n/locales/en/tickets.json";
|
||||
import enWallet from "@/i18n/locales/en/wallet.json";
|
||||
|
||||
const EN_FLAT: Record<string, Record<string, unknown>> = {
|
||||
dashboard: enDashboard,
|
||||
players: enPlayers,
|
||||
draws: enDraws,
|
||||
tickets: enTickets,
|
||||
settlement: enSettlement,
|
||||
reconcile: enReconcile,
|
||||
audit: enAudit,
|
||||
adminUsers: enAdminUsers,
|
||||
adminRoles: enAdminRoles,
|
||||
wallet: enWallet,
|
||||
risk: enRisk,
|
||||
jackpot: enJackpot,
|
||||
config: enConfig,
|
||||
common: enCommon,
|
||||
auth: enAuth,
|
||||
};
|
||||
|
||||
function getByPath(obj: Record<string, unknown>, path: string): string | undefined {
|
||||
const parts = path.split(".");
|
||||
let cur: unknown = obj;
|
||||
for (const part of parts) {
|
||||
if (cur == null || typeof cur !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
cur = (cur as Record<string, unknown>)[part];
|
||||
}
|
||||
return typeof cur === "string" ? cur : undefined;
|
||||
}
|
||||
|
||||
/** SSR 默认英文标题;客户端由 {@link AdminDocumentTitle} 按用户语言覆盖。 */
|
||||
export function buildPageMetadata(ns: string, key: string): Metadata {
|
||||
const bundle = EN_FLAT[ns];
|
||||
const title = bundle ? getByPath(bundle as Record<string, unknown>, key) : undefined;
|
||||
|
||||
return {
|
||||
title: title ?? key,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user