refactor: 完成全站国际化改造,统一多语言支持
此提交完成了全项目的国际化适配: 1. 新增多语言翻译文件与基础配置 2. 替换所有硬编码文本为i18n调用 3. 优化语言切换与文档语言同步逻辑 4. 重构部分业务逻辑以支持动态翻译 5. 移除过时代码与硬编码配置
This commit is contained in:
@@ -32,3 +32,13 @@ const LABELS: Record<string, string> = {
|
||||
export function playLabelZh(playCode: string): string {
|
||||
return LABELS[playCode] ?? playCode;
|
||||
}
|
||||
|
||||
export function playLabel(
|
||||
playCode: string,
|
||||
t?: (key: string, options?: { defaultValue?: string }) => string,
|
||||
): string {
|
||||
if (!t) {
|
||||
return playLabelZh(playCode);
|
||||
}
|
||||
return t(`playLabels.${playCode}`, { defaultValue: LABELS[playCode] ?? playCode });
|
||||
}
|
||||
|
||||
@@ -3,30 +3,37 @@ import { isAxiosError } from "axios";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
|
||||
/** 钱包 / 转账 API 对用户展示的中文说明(优先业务码,其次 HTTP) */
|
||||
export function formatWalletClientError(error: unknown): string {
|
||||
export function formatWalletClientError(
|
||||
error: unknown,
|
||||
t?: (key: string) => string,
|
||||
): string {
|
||||
if (error instanceof LotteryApiBizError) {
|
||||
const m = WALLET_CODE_MESSAGES[error.code];
|
||||
const m = walletCodeMessage(error.code, t);
|
||||
if (m) return m;
|
||||
if (error.message.trim()) return error.message;
|
||||
}
|
||||
if (isAxiosError(error)) {
|
||||
if (error.response?.status === 401) {
|
||||
return "登录已失效,请返回重新进入。";
|
||||
return msg(t, "wallet.error.401", "登录已失效,请返回重新进入。");
|
||||
}
|
||||
if (error.response?.status === 409) {
|
||||
return "转账处理中,请稍后刷新;若长时间未到账请联系客服。";
|
||||
return msg(
|
||||
t,
|
||||
"wallet.error.409",
|
||||
"转账处理中,请稍后刷新;若长时间未到账请联系客服。",
|
||||
);
|
||||
}
|
||||
if (!error.response) {
|
||||
return "网络异常,请检查连接后重试。";
|
||||
return msg(t, "wallet.error.network", "网络异常,请检查连接后重试。");
|
||||
}
|
||||
if (error.code === "ECONNABORTED") {
|
||||
return "请求超时,请稍后重试。";
|
||||
return msg(t, "wallet.error.timeout", "请求超时,请稍后重试。");
|
||||
}
|
||||
}
|
||||
if (error instanceof Error && error.message.trim()) {
|
||||
return error.message;
|
||||
}
|
||||
return "请求失败,请稍后重试。";
|
||||
return msg(t, "wallet.error.fallback", "请求失败,请稍后重试。");
|
||||
}
|
||||
|
||||
const WALLET_CODE_MESSAGES: Record<number, string> = {
|
||||
@@ -41,3 +48,20 @@ const WALLET_CODE_MESSAGES: Record<number, string> = {
|
||||
1009: "主站未能完成本次划转,请稍后重试。",
|
||||
1010: "请勿用同一幂等键发起不同金额的转账。",
|
||||
};
|
||||
|
||||
function msg(
|
||||
t: ((key: string) => string) | undefined,
|
||||
key: string,
|
||||
fallback: string,
|
||||
): string {
|
||||
return t?.(key) ?? fallback;
|
||||
}
|
||||
|
||||
function walletCodeMessage(
|
||||
code: number,
|
||||
t: ((key: string) => string) | undefined,
|
||||
): string | undefined {
|
||||
const fallback = WALLET_CODE_MESSAGES[code];
|
||||
if (!fallback) return undefined;
|
||||
return msg(t, `wallet.error.${code}`, fallback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user