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
+15 -3
View File
@@ -1,13 +1,25 @@
import { useTranslation } from 'react-i18next';
import { useQrState } from '../store/qrContext';
import { MODES, MODE_LABELS } from '../types';
import { MODES } from '../types';
const MODE_LABELS: Record<string, string> = {
text: 'mode.text',
url: 'mode.url',
wifi: 'mode.wifi',
vcard: 'mode.vcard',
email: 'mode.email',
phone: 'mode.phone',
sms: 'mode.sms',
};
export default function ModePanel() {
const { t } = useTranslation();
const { state, dispatch } = useQrState();
return (
<div className="w-48 border-r border-gray-200 dark:border-gray-800 p-3 flex flex-col gap-1 bg-white/60 dark:bg-gray-900/60 backdrop-blur-sm">
<div className="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-2">
{t('app.encodingModes')}
</div>
{MODES.map((mode) => (
<button
@@ -19,7 +31,7 @@ export default function ModePanel() {
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800'
}`}
>
{MODE_LABELS[mode]}
{t(MODE_LABELS[mode])}
</button>
))}
</div>