feat: 增加管理端多语言与风控/报表/奖池操作能力
This commit is contained in:
98
src/i18n/index.ts
Normal file
98
src/i18n/index.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
"use client";
|
||||
|
||||
import i18n from "i18next";
|
||||
import LanguageDetector from "i18next-browser-languagedetector";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
|
||||
import { adminHtmlLang, applyAdminUiLocale, type AdminApiLocale } from "@/lib/admin-locale";
|
||||
import enAudit from "@/i18n/locales/en/audit.json";
|
||||
import enAuth from "@/i18n/locales/en/auth.json";
|
||||
import enCommon from "@/i18n/locales/en/common.json";
|
||||
import enDashboard from "@/i18n/locales/en/dashboard.json";
|
||||
import enReports from "@/i18n/locales/en/reports.json";
|
||||
import neAudit from "@/i18n/locales/ne/audit.json";
|
||||
import neAuth from "@/i18n/locales/ne/auth.json";
|
||||
import neCommon from "@/i18n/locales/ne/common.json";
|
||||
import neDashboard from "@/i18n/locales/ne/dashboard.json";
|
||||
import neReports from "@/i18n/locales/ne/reports.json";
|
||||
import zhAudit from "@/i18n/locales/zh/audit.json";
|
||||
import zhAuth from "@/i18n/locales/zh/auth.json";
|
||||
import zhCommon from "@/i18n/locales/zh/common.json";
|
||||
import zhDashboard from "@/i18n/locales/zh/dashboard.json";
|
||||
import zhReports from "@/i18n/locales/zh/reports.json";
|
||||
|
||||
export const ADMIN_SUPPORTED_LANGUAGES = ["en", "ne", "zh"] as const;
|
||||
export type AdminLanguage = (typeof ADMIN_SUPPORTED_LANGUAGES)[number];
|
||||
export const ADMIN_DEFAULT_LANGUAGE: AdminLanguage = "en";
|
||||
|
||||
const namespaces = ["common", "auth", "dashboard", "reports", "audit"] as const;
|
||||
|
||||
const resources = {
|
||||
en: {
|
||||
common: enCommon,
|
||||
auth: enAuth,
|
||||
dashboard: enDashboard,
|
||||
reports: enReports,
|
||||
audit: enAudit,
|
||||
},
|
||||
ne: {
|
||||
common: neCommon,
|
||||
auth: neAuth,
|
||||
dashboard: neDashboard,
|
||||
reports: neReports,
|
||||
audit: neAudit,
|
||||
},
|
||||
zh: {
|
||||
common: zhCommon,
|
||||
auth: zhAuth,
|
||||
dashboard: zhDashboard,
|
||||
reports: zhReports,
|
||||
audit: zhAudit,
|
||||
},
|
||||
} satisfies Record<AdminLanguage, Record<(typeof namespaces)[number], Record<string, unknown>>>;
|
||||
|
||||
function normalizeAdminLanguage(lang: string | undefined): AdminLanguage {
|
||||
const base = lang?.split("-")[0]?.toLowerCase();
|
||||
if (base === "ne") return "ne";
|
||||
if (base === "zh") return "zh";
|
||||
return "en";
|
||||
}
|
||||
|
||||
function syncAdminLanguage(lang: AdminLanguage): void {
|
||||
if (typeof document !== "undefined") {
|
||||
document.documentElement.lang = adminHtmlLang(lang);
|
||||
}
|
||||
applyAdminUiLocale(lang as AdminApiLocale);
|
||||
}
|
||||
|
||||
if (!i18n.isInitialized) {
|
||||
void i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources,
|
||||
fallbackLng: ADMIN_DEFAULT_LANGUAGE,
|
||||
supportedLngs: [...ADMIN_SUPPORTED_LANGUAGES],
|
||||
defaultNS: "common",
|
||||
ns: [...namespaces],
|
||||
load: "languageOnly",
|
||||
detection: {
|
||||
order: ["localStorage", "navigator"],
|
||||
caches: ["localStorage"],
|
||||
lookupLocalStorage: "lottery_admin_ui_locale",
|
||||
},
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
react: {
|
||||
useSuspense: false,
|
||||
},
|
||||
});
|
||||
|
||||
syncAdminLanguage(normalizeAdminLanguage(i18n.resolvedLanguage ?? i18n.language));
|
||||
i18n.on("languageChanged", (lang) => {
|
||||
syncAdminLanguage(normalizeAdminLanguage(lang));
|
||||
});
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
3
src/i18n/locales/en/audit.json
Normal file
3
src/i18n/locales/en/audit.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "Audit Logs"
|
||||
}
|
||||
3
src/i18n/locales/en/auth.json
Normal file
3
src/i18n/locales/en/auth.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "Login"
|
||||
}
|
||||
20
src/i18n/locales/en/common.json
Normal file
20
src/i18n/locales/en/common.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"language": {
|
||||
"en": "English",
|
||||
"ne": "नेपाली",
|
||||
"zh": "中文",
|
||||
"title": "Interface language",
|
||||
"changed": "Language"
|
||||
},
|
||||
"app": {
|
||||
"title": "Lottery Admin"
|
||||
},
|
||||
"actions": {
|
||||
"refresh": "Refresh",
|
||||
"download": "Download",
|
||||
"search": "Search",
|
||||
"apply": "Apply",
|
||||
"loading": "Loading...",
|
||||
"submitting": "Submitting..."
|
||||
}
|
||||
}
|
||||
3
src/i18n/locales/en/dashboard.json
Normal file
3
src/i18n/locales/en/dashboard.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "Dashboard"
|
||||
}
|
||||
3
src/i18n/locales/en/reports.json
Normal file
3
src/i18n/locales/en/reports.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "Reports"
|
||||
}
|
||||
3
src/i18n/locales/ne/audit.json
Normal file
3
src/i18n/locales/ne/audit.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "अडिट लग"
|
||||
}
|
||||
3
src/i18n/locales/ne/auth.json
Normal file
3
src/i18n/locales/ne/auth.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "लगइन"
|
||||
}
|
||||
20
src/i18n/locales/ne/common.json
Normal file
20
src/i18n/locales/ne/common.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"language": {
|
||||
"en": "English",
|
||||
"ne": "नेपाली",
|
||||
"zh": "中文",
|
||||
"title": "इन्टरफेस भाषा",
|
||||
"changed": "भाषा"
|
||||
},
|
||||
"app": {
|
||||
"title": "Lottery Admin"
|
||||
},
|
||||
"actions": {
|
||||
"refresh": "रिफ्रेस",
|
||||
"download": "डाउनलोड",
|
||||
"search": "खोज",
|
||||
"apply": "लागू गर्नुहोस्",
|
||||
"loading": "लोड हुँदैछ...",
|
||||
"submitting": "पेश हुँदैछ..."
|
||||
}
|
||||
}
|
||||
3
src/i18n/locales/ne/dashboard.json
Normal file
3
src/i18n/locales/ne/dashboard.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "ड्यासबोर्ड"
|
||||
}
|
||||
3
src/i18n/locales/ne/reports.json
Normal file
3
src/i18n/locales/ne/reports.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "रिपोर्ट"
|
||||
}
|
||||
3
src/i18n/locales/zh/audit.json
Normal file
3
src/i18n/locales/zh/audit.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "审计日志"
|
||||
}
|
||||
3
src/i18n/locales/zh/auth.json
Normal file
3
src/i18n/locales/zh/auth.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "登录"
|
||||
}
|
||||
20
src/i18n/locales/zh/common.json
Normal file
20
src/i18n/locales/zh/common.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"language": {
|
||||
"en": "English",
|
||||
"ne": "नेपाली",
|
||||
"zh": "中文",
|
||||
"title": "界面语言",
|
||||
"changed": "语言"
|
||||
},
|
||||
"app": {
|
||||
"title": "彩票后台"
|
||||
},
|
||||
"actions": {
|
||||
"refresh": "刷新",
|
||||
"download": "下载",
|
||||
"search": "搜索",
|
||||
"apply": "应用",
|
||||
"loading": "加载中...",
|
||||
"submitting": "提交中..."
|
||||
}
|
||||
}
|
||||
3
src/i18n/locales/zh/dashboard.json
Normal file
3
src/i18n/locales/zh/dashboard.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "仪表盘"
|
||||
}
|
||||
3
src/i18n/locales/zh/reports.json
Normal file
3
src/i18n/locales/zh/reports.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "报表"
|
||||
}
|
||||
Reference in New Issue
Block a user