Skip to content

Commit 39b4b2f

Browse files
committed
Merge branch 'v3.x-beta' of github.com:NodePassProject/NodePassDash into v3.x-beta
2 parents 30a18f4 + d8332b2 commit 39b4b2f

File tree

8 files changed

+495
-1
lines changed

8 files changed

+495
-1
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,9 @@ logs/
8585
certs/
8686
gob/
8787
pkg/
88+
nodepassdash
89+
90+
# vibe coding
8891
CLAUDE.md
89-
nodepassdash
92+
AGENTS.md
93+
/docs/dev/*

web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
"clsx": "2.1.1",
3434
"date-fns": "^4.1.0",
3535
"framer-motion": "11.18.2",
36+
"i18next": "^25.6.3",
37+
"i18next-browser-languagedetector": "^8.2.0",
3638
"next-themes": "^0.2.1",
3739
"qrcode": "^1.5.0",
3840
"react": "18.3.1",
3941
"react-dom": "18.3.1",
4042
"react-hook-form": "^7.45.0",
43+
"react-i18next": "^16.3.5",
4144
"react-json-editor-ajrm": "^2.5.14",
4245
"react-markdown": "^10.1.0",
4346
"react-router-dom": "6.23.0",

web/pnpm-lock.yaml

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/lib/i18n.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import i18n from "i18next";
2+
import { initReactI18next } from "react-i18next";
3+
import LanguageDetector from "i18next-browser-languagedetector";
4+
5+
// 导入翻译资源
6+
import commonZh from "@/locales/zh-CN/common.json";
7+
import authZh from "@/locales/zh-CN/auth.json";
8+
import commonEn from "@/locales/en-US/common.json";
9+
import authEn from "@/locales/en-US/auth.json";
10+
11+
// 定义支持的语言
12+
export const supportedLanguages = ["zh-CN", "en-US"] as const;
13+
export type SupportedLanguage = (typeof supportedLanguages)[number];
14+
15+
// 定义翻译资源类型
16+
export const resources = {
17+
"zh-CN": {
18+
common: commonZh,
19+
auth: authZh,
20+
},
21+
"en-US": {
22+
common: commonEn,
23+
auth: authEn,
24+
},
25+
} as const;
26+
27+
// 初始化i18next
28+
i18n
29+
.use(LanguageDetector) // 自动检测浏览器语言
30+
.use(initReactI18next) // 集成React
31+
.init({
32+
resources,
33+
fallbackLng: "zh-CN", // 默认语言为中文
34+
defaultNS: "common", // 默认命名空间
35+
ns: ["common", "auth"], // 可用的命名空间
36+
37+
// 语言检测配置
38+
detection: {
39+
// 检测顺序:localStorage -> 浏览器语言 -> 默认语言
40+
order: ["localStorage", "navigator"],
41+
// 缓存用户选择的语言
42+
caches: ["localStorage"],
43+
// localStorage中的key
44+
lookupLocalStorage: "nodepass-language",
45+
},
46+
47+
interpolation: {
48+
escapeValue: false, // React已经处理了XSS防护
49+
},
50+
51+
react: {
52+
useSuspense: false, // 禁用Suspense,避免闪烁
53+
},
54+
});
55+
56+
export default i18n;

web/src/locales/en-US/auth.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"login": {
3+
"title": "NodePassDash",
4+
"subtitle": "Please enter your credentials",
5+
"username": "Username",
6+
"password": "Password",
7+
"usernamePlaceholder": "Enter your username",
8+
"passwordPlaceholder": "Enter your password",
9+
"submit": "Sign In",
10+
"submitting": "Signing in...",
11+
"divider": "Or sign in with",
12+
"dividerLoginDisabled": "Please sign in with",
13+
"githubLogin": "Sign in with GitHub",
14+
"cloudflareLogin": "Sign in with Cloudflare",
15+
"systemError": "System Configuration Error",
16+
"systemErrorMessage": "System configuration error: Password login is disabled but OAuth2 is not configured. Please contact the administrator"
17+
},
18+
"error": {
19+
"loginFailed": "Login failed",
20+
"networkError": "Network error, please try again later",
21+
"invalidCredentials": "Invalid username or password",
22+
"unauthorized": "Unauthorized",
23+
"sessionExpired": "Session expired, please sign in again"
24+
},
25+
"oauth": {
26+
"error": "OAuth login failed",
27+
"cancelled": "Authorization cancelled by user",
28+
"stateMismatch": "State verification failed",
29+
"configError": "OAuth configuration error"
30+
},
31+
"logout": {
32+
"title": "Sign Out",
33+
"confirm": "Are you sure you want to sign out?",
34+
"success": "Signed out successfully"
35+
}
36+
}

0 commit comments

Comments
 (0)