feat: i18n (i18next + react-i18next) zh/en + hydration fixes

- i18next + react-i18next: zh/en locales, language detection
  (localStorage > navigator > zh), settings language switcher
- Components i18n'd: Navbar, Feed, NewPost, Modals, SettingsPage,
  SettingsProfile, AccountSecurity, RecoveryCodes
- Fix hydration mismatch (spinner restart): forum name via cookie
  (Server Component reads cookie, SSR outputs name, no inline script
  DOM injection); remove createPortal in RecoveryCodes modal; i18n
  sync init (initImmediate) so SSR/CSR text matches
- LoadingScreen: React-state name rendering (no script-injected nodes)
- Fix double spinner in Feed; DM icon emoji → SVG in ConversationList

# Conflicts:
#	components/AppProvider.js
#	components/NewPost.js
This commit is contained in:
lezi-fun committed 2026-08-11 11:33:57 +08:00
1 parent 024b678ad3
commit 1934edebd5
20 files changed
+600 -169

No files matched your search

+25 -1
View File
@@ -1,12 +1,15 @@
'use client';
// 设置 - 个人资料(头像 + 用户名/简介/签名)
// 设置 - 个人资料(头像 + 用户名/简介/签名 + 语言)
import { useState, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { API, uploadImage } from '@/lib/api';
import { useApp } from './AppProvider';
import { setAppLanguage } from '@/lib/i18n';
export default function SettingsProfile() {
const { currentUser, setCurrentUser } = useApp();
const { t, i18n } = useTranslation();
const [username, setUsername] = useState(currentUser?.username || '');
const [bio, setBio] = useState(currentUser?.bio || '');
const [signature, setSignature] = useState(currentUser?.signature || '');
@@ -82,6 +85,27 @@ export default function SettingsProfile() {
</div>
<button className="btn-primary" style={{ width: '100%', padding: 10 }} onClick={handleSave}>保存设置</button>
</div>
{/* 语言设置 */}
<div style={{ background: 'var(--surface)', border: '1px solid var(--border)', borderRadius: 8, padding: 20, marginTop: 16 }}>
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 8 }}>{t('settings.language')}</label>
<div style={{ display: 'flex', gap: 10 }}>
<button
className={'btn' + (i18n.language === 'zh' ? ' btn-primary' : '')}
style={{ padding: '8px 20px', borderRadius: 6, cursor: 'pointer', border: '1px solid var(--border)', background: i18n.language === 'zh' ? 'var(--primary)' : 'transparent', color: i18n.language === 'zh' ? '#fff' : 'var(--text)' }}
onClick={() => setAppLanguage('zh')}
>
{t('settings.languageZh')}
</button>
<button
className={'btn' + (i18n.language === 'en' ? ' btn-primary' : '')}
style={{ padding: '8px 20px', borderRadius: 6, cursor: 'pointer', border: '1px solid var(--border)', background: i18n.language === 'en' ? 'var(--primary)' : 'transparent', color: i18n.language === 'en' ? '#fff' : 'var(--text)' }}
onClick={() => setAppLanguage('en')}
>
{t('settings.languageEn')}
</button>
</div>
</div>
</div>
);
}