feat: i18n 中英双语界面 — i18next + react-i18next

- 安装 i18next / react-i18next / i18next-browser-languagedetector
- 新建 src/i18n.ts 配置(fallback zh)
- 中/英翻译文件各 ~50 条目
- App.tsx 新增 EN/中 语言切换按钮
- ExportPanel + QrPreview + ModePanel + HistoryList + ErrorBoundary
- 全部 7 种模式组件均支持双语
- 12 前端测试通过,tsc 零错误
This commit is contained in:
2026-06-19 21:23:10 +08:00
parent 8e9e7e1b4c
commit 77fac0e28f
19 changed files with 381 additions and 56 deletions
+8 -6
View File
@@ -1,16 +1,18 @@
import { useTranslation } from 'react-i18next';
import { useQrState } from '../store/qrContext';
import { useQrEncode } from '../hooks/useQrEncode';
import { buildVCardText } from '../utils/qrText';
const FIELDS = [
{ key: 'name', placeholder: '姓名' },
{ key: 'phone', placeholder: '电话' },
{ key: 'email', placeholder: '邮箱' },
{ key: 'company', placeholder: '公司' },
{ key: 'address', placeholder: '地址' },
{ key: 'name', i18n: 'vcard.name' },
{ key: 'phone', i18n: 'vcard.phone' },
{ key: 'email', i18n: 'vcard.email' },
{ key: 'company', i18n: 'vcard.company' },
{ key: 'address', i18n: 'vcard.address' },
];
export default function VCardMode() {
const { t } = useTranslation();
const { state, dispatch } = useQrState();
const { encode } = useQrEncode();
@@ -25,7 +27,7 @@ export default function VCardMode() {
{FIELDS.map((f) => (
<input
key={f.key}
placeholder={f.placeholder}
placeholder={t(f.i18n)}
value={state.formData[f.key] || ''}
onChange={(e) => update(f.key, e.target.value)}
className="flex-1 px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 text-sm bg-transparent outline-none focus:ring-2 focus:ring-blue-500/30"