-
✉️ 私信
+ 私信
×
diff --git a/lib/i18n.js b/lib/i18n.js
new file mode 100644
index 0000000..c07b627
--- /dev/null
+++ b/lib/i18n.js
@@ -0,0 +1,41 @@
+'use client';
+
+// i18n 配置:i18next + react-i18next
+// - 模块顶层无条件 init(SSR Node 与客户端都执行):SSR 输出用默认 zh,
+// 与客户端初始语言一致 → 无 hydration mismatch
+// - initI18n() 在客户端按 localStorage/浏览器语言切换;SSR 时 no-op
+import i18n from 'i18next';
+import { initReactI18next } from 'react-i18next';
+import zh from '@/locales/zh.json';
+import en from '@/locales/en.json';
+
+i18n.use(initReactI18next).init({
+ resources: {
+ zh: { translation: zh },
+ en: { translation: en },
+ },
+ lng: 'zh',
+ fallbackLng: 'zh',
+ interpolation: { escapeValue: false },
+ react: { useSuspense: false },
+ // 同步初始化:SSR 渲染时 t() 立即返回翻译(否则返回 key → hydration mismatch)
+ initImmediate: false,
+});
+
+// 客户端初始化:按 localStorage / 浏览器语言切换(SSR 阶段 no-op)
+export function initI18n() {
+ if (typeof window === 'undefined') return i18n;
+ try {
+ const saved = localStorage.getItem('forumlify-lang');
+ const nav = (navigator.language || 'zh').toLowerCase();
+ const lng = saved || (nav.startsWith('en') ? 'en' : 'zh');
+ if (i18n.language !== lng) i18n.changeLanguage(lng);
+ } catch (e) {}
+ return i18n;
+}
+
+// 切换语言(保存到 localStorage)
+export function setAppLanguage(lng) {
+ if (typeof window !== 'undefined') localStorage.setItem('forumlify-lang', lng);
+ return i18n.changeLanguage(lng);
+}
diff --git a/locales/en.json b/locales/en.json
new file mode 100644
index 0000000..a3ecc07
--- /dev/null
+++ b/locales/en.json
@@ -0,0 +1,154 @@
+{
+ "appName": "Forumlify",
+ "nav": {
+ "home": "Home",
+ "messages": "Messages",
+ "settings": "Settings",
+ "admin": "Admin",
+ "login": "Login",
+ "register": "Register",
+ "logout": "Logout",
+ "darkMode": "Dark mode",
+ "lightMode": "Light mode",
+ "logoutConfirm": "Are you sure you want to log out?"
+ },
+ "feed": {
+ "latest": "Latest posts",
+ "hot": "Latest replies",
+ "newPost": "New post",
+ "loading": "Loading...",
+ "empty": "✨ No posts yet — be the first to publish!",
+ "pinned": "📌 Pinned",
+ "deleted": "(edited)",
+ "report": "Report",
+ "delete": "Delete",
+ "confirmDelete": "Are you sure you want to delete this post?",
+ "deleteFailed": "Delete failed: {{msg}}",
+ "noTitle": "Untitled",
+ "anonymous": "Anonymous"
+ },
+ "post": {
+ "title": "Post detail",
+ "back": "← Back",
+ "edit": "Edit",
+ "save": "Save",
+ "cancel": "Cancel",
+ "editFailed": "Load failed: {{msg}}",
+ "contentRequired": "Please fill in the content",
+ "reply": "Reply",
+ "replyCount": "{{count}} replies",
+ "reportReason": "Report reason",
+ "confirmDelete": "Are you sure you want to delete this post?",
+ "reportTitle": "Report post",
+ "submitReport": "Submit report"
+ },
+ "newPost": {
+ "title": "Title",
+ "content": "Say something...",
+ "publish": "Publish post",
+ "uploading": "Uploading...",
+ "pleaseLogin": "Please log in first",
+ "captchaError": "Wrong captcha, please try again",
+ "publishSuccess": "Post published",
+ "publishFailed": "Publish failed: {{msg}}",
+ "answer": "Answer",
+ "captchaLoading": "Loading captcha...",
+ "drop": "Release to upload",
+ "dropHint": "Click or drag to upload image"
+ },
+ "reply": {
+ "submit": "Submit reply",
+ "placeholder": "Write your reply...",
+ "empty": "No replies yet — be the first to comment 🛋️",
+ "replyFailed": "Reply failed: {{msg}}",
+ "delete": "Delete",
+ "confirmDelete": "Are you sure you want to delete this reply?",
+ "deleteFailed": "Delete failed: {{msg}}"
+ },
+ "auth": {
+ "email": "Email",
+ "password": "Password",
+ "username": "Username",
+ "passwordHint": "Password (min 6 chars)",
+ "forgotPassword": "Forgot password?",
+ "captchaError": "Wrong captcha, please try again",
+ "registerSuccess": "🎉 Registration successful",
+ "loginSuccess": "Logged in",
+ "logoutSuccess": "Logged out",
+ "login": "Login",
+ "register": "Register"
+ },
+ "settings": {
+ "title": "Settings",
+ "profile": "Profile",
+ "security": "Security",
+ "recovery": "Recovery codes",
+ "language": "Language",
+ "languageZh": "中文",
+ "languageEn": "English",
+ "username": "Username",
+ "bio": "Bio",
+ "signature": "Signature",
+ "save": "Save settings",
+ "saved": "Saved!",
+ "saveFailed": "Save failed: {{msg}}",
+ "usernameRequired": "Username cannot be empty",
+ "pleaseLogin": "Please log in first"
+ },
+ "user": {
+ "title": "User profile",
+ "bioEmpty": "This user hasn't written a bio yet",
+ "sendMessage": "Send message",
+ "joined": "📅 Joined {{date}}",
+ "posts": "📝 {{count}} posts",
+ "admin": "🛡️ Admin",
+ "noPosts": "No posts yet",
+ "notFound": "User not found",
+ "loading": "Loading..."
+ },
+ "stats": {
+ "topics": "Topics",
+ "posts": "Posts",
+ "users": "Users",
+ "links": "Links"
+ },
+ "loading": "Loading...",
+ "common": {
+ "confirm": "Confirm",
+ "cancel": "Cancel",
+ "close": "Close"
+ },
+ "report": {
+ "spam": "Spam",
+ "abuse": "Harassment",
+ "illegal": "Illegal content",
+ "nsfw": "Inappropriate content",
+ "other": "Other"
+ },
+ "security": {
+ "title": "Account security",
+ "currentPw": "Current password",
+ "newPw": "New password",
+ "changePw": "Change password",
+ "currentPwVerify": "Current password (verify identity)",
+ "newEmail": "New email",
+ "changeEmail": "Change email",
+ "fillAll": "Please fill in all fields",
+ "pwMin": "New password must be at least 6 characters",
+ "pwChanged": "✅ Password changed",
+ "emailChanged": "✅ Email changed"
+ },
+ "recovery": {
+ "title": "Recovery codes",
+ "desc": "Use these to reset your account if you forget your password. Each code works once.",
+ "view": "View recovery codes",
+ "regenerate": "Regenerate",
+ "remaining": "{{count}} recovery codes remaining",
+ "confirmRegenerate": "Regenerating will invalidate all old codes. Continue?",
+ "genFailed": "Generation failed: {{msg}}",
+ "fetchFailed": "Fetch failed: {{msg}}",
+ "newCodes": "🆕 New recovery codes",
+ "saveWarning": "⚠️ Save these codes now — they cannot be viewed again after closing.",
+ "saved": "I have saved them"
+ }
+}
\ No newline at end of file
diff --git a/locales/zh.json b/locales/zh.json
new file mode 100644
index 0000000..d7c8911
--- /dev/null
+++ b/locales/zh.json
@@ -0,0 +1,151 @@
+{
+ "appName": "Forumlify",
+ "nav": {
+ "home": "首页",
+ "messages": "消息",
+ "settings": "设置",
+ "admin": "管理后台",
+ "login": "登录",
+ "register": "注册",
+ "logout": "退出",
+ "darkMode": "暗色模式",
+ "lightMode": "亮色模式",
+ "logoutConfirm": "确定要退出吗?"
+ },
+ "feed": {
+ "latest": "最新发布",
+ "hot": "最新回复",
+ "newPost": "发布新帖",
+ "loading": "加载中...",
+ "empty": "✨ 还没有帖子,快来发布第一条吧!",
+ "pinned": "📌 置顶",
+ "deleted": "(已编辑)",
+ "report": "举报",
+ "delete": "删除",
+ "confirmDelete": "确定要删除这条帖子吗?",
+ "deleteFailed": "删除失败:{{msg}}",
+ "noTitle": "无标题",
+ "anonymous": "匿名用户"
+ },
+ "post": {
+ "title": "帖子详情",
+ "back": "← 返回",
+ "edit": "编辑",
+ "save": "保存",
+ "cancel": "取消",
+ "editFailed": "加载失败:{{msg}}",
+ "contentRequired": "请填写内容",
+ "reply": "回复",
+ "replyCount": "{{count}} 条回复",
+ "reportReason": "举报原因",
+ "confirmDelete": "确定要删除这条帖子吗?",
+ "reportTitle": "举报帖子",
+ "submitReport": "提交举报"
+ },
+ "newPost": {
+ "title": "标题",
+ "content": "说点什么...",
+ "publish": "发布帖子",
+ "uploading": "上传中...",
+ "pleaseLogin": "请先登录",
+ "captchaError": "验证码错误,请重新计算",
+ "publishSuccess": "发布成功",
+ "publishFailed": "发布失败:{{msg}}",
+ "answer": "答案",
+ "captchaLoading": "验证码加载中...",
+ "drop": "松开上传",
+ "dropHint": "点击或拖拽上传图片"
+ },
+ "reply": {
+ "submit": "提交回复",
+ "placeholder": "写下你的回复...",
+ "empty": "还没有回复,快来抢沙发吧 🛋️",
+ "replyFailed": "回复失败:{{msg}}",
+ "delete": "删除",
+ "confirmDelete": "确定要删除这条回复吗?",
+ "deleteFailed": "删除失败:{{msg}}"
+ },
+ "auth": {
+ "email": "邮箱",
+ "password": "密码",
+ "username": "用户名",
+ "passwordHint": "密码(至少6位)",
+ "forgotPassword": "忘记密码?",
+ "captchaError": "验证码错误,请重新计算",
+ "registerSuccess": "🎉 注册成功",
+ "loginSuccess": "登录成功",
+ "logoutSuccess": "已退出登录",
+ "login": "登录",
+ "register": "注册"
+ },
+ "settings": {
+ "title": "设置",
+ "profile": "个人资料",
+ "security": "安全设置",
+ "recovery": "恢复码",
+ "username": "用户名",
+ "bio": "个人简介",
+ "signature": "个性签名",
+ "save": "保存设置",
+ "saved": "保存成功!",
+ "saveFailed": "保存失败:{{msg}}",
+ "usernameRequired": "用户名不能为空",
+ "pleaseLogin": "请先登录"
+ },
+ "user": {
+ "title": "用户主页",
+ "bioEmpty": "这个人很懒,什么都没写",
+ "sendMessage": "发私信",
+ "joined": "📅 加入于 {{date}}",
+ "posts": "📝 发了 {{count}} 个帖子",
+ "admin": "🛡️ 管理员",
+ "noPosts": "还没有发帖",
+ "notFound": "用户不存在",
+ "loading": "加载中..."
+ },
+ "stats": {
+ "topics": "主题",
+ "posts": "帖子",
+ "users": "用户",
+ "links": "友情链接"
+ },
+ "loading": "加载中...",
+ "common": {
+ "confirm": "确定",
+ "cancel": "取消",
+ "close": "关闭"
+ },
+ "report": {
+ "spam": "垃圾广告",
+ "abuse": "人身攻击",
+ "illegal": "违法内容",
+ "nsfw": "不适当内容",
+ "other": "其他"
+ },
+ "security": {
+ "title": "账户安全",
+ "currentPw": "当前密码",
+ "newPw": "新密码",
+ "changePw": "修改密码",
+ "currentPwVerify": "当前密码(验证身份)",
+ "newEmail": "新邮箱",
+ "changeEmail": "修改邮箱",
+ "fillAll": "请填写完整信息",
+ "pwMin": "新密码至少6位",
+ "pwChanged": "✅ 密码修改成功",
+ "emailChanged": "✅ 邮箱修改成功"
+ },
+ "recovery": {
+ "title": "恢复码",
+ "desc": "用于忘记密码时重置账户。每个恢复码只能使用一次。",
+ "view": "查看恢复码",
+ "regenerate": "重新生成",
+ "remaining": "剩余 {{count}} 个可用恢复码",
+ "confirmRegenerate": "重新生成将使所有旧恢复码失效,确定继续吗?",
+ "genFailed": "生成失败:{{msg}}",
+ "fetchFailed": "获取失败:{{msg}}",
+ "newCodes": "🆕 新恢复码",
+ "saveWarning": "⚠️ 请妥善保存这些恢复码,关闭窗口后无法再次查看。",
+ "saved": "我已保存"
+ }
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index e29128d..915f6e0 100644
--- a/package.json
+++ b/package.json
@@ -16,12 +16,14 @@
"dependencies": {
"aws4fetch": "^1.0.20",
"bcryptjs": "^3.0.3",
+ "i18next": "^26.3.6",
"jsonwebtoken": "^9.0.2",
"marked": "^18.0.9",
"next": "16",
"pg": "^8.11.3",
"react": "19",
- "react-dom": "19"
+ "react-dom": "19",
+ "react-i18next": "^17.0.11"
},
"devDependencies": {
"@opennextjs/cloudflare": "^1.20.2",