refactor: 迁移 i18n 系统从 react-i18next 到 chrome.i18n

- 移除 react-i18next、i18next 及相关依赖
- 删除旧的 i18n/ 目录和 useLazyTranslation 工具
- 新增 utils/chromeI18n.ts 类型安全 wrapper(useI18n Hook + getMessage)
- 生成 public/_locales/{zh,en}/messages.json(298 个翻译 key)
- 批量更新 39+ 组件文件的导入和翻译调用
- 转换翻译键格式:namespace:key → namespace_key
- 修复 ErrorBoundary/PageErrorBoundary 从 withTranslation HOC 改为直接调用 getMessage
- 更新 vitest.setup.ts mock 加载实际翻译文本
- 修复 11 个测试文件的断言以匹配中文翻译
- TypeScript、ESLint、547 项测试全部通过

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
雨霖铃
2026-05-28 19:21:54 +08:00
parent 64e23994a6
commit aa23a263fe
94 changed files with 2987 additions and 1844 deletions
+4 -4
View File
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { parseJwt, stringifyJson } from '@/utils/jwt';
import CopyButton from '@/components/CopyButton';
import TextInputArea from '@/components/TextInputArea';
import { useLazyTranslation } from '@/utils/useLazyTranslation';
import { useI18n } from '@/utils/chromeI18n';
import { useContextMenuData } from '@/utils/useContextMenuData';
import { cn } from '@/lib/utils';
@@ -15,7 +15,7 @@ interface SectionProps {
}
const Section = ({ title, content, colorClass, bgClass, borderClass }: SectionProps) => {
const { t } = useLazyTranslation('jwt');
const { t } = useI18n('jwt');
return (
<div className={cn('p-4 rounded-xl border border-solid', bgClass, borderClass)}>
<div className="flex justify-between items-center mb-2 select-none">
@@ -39,7 +39,7 @@ const Section = ({ title, content, colorClass, bgClass, borderClass }: SectionPr
};
export default function Index() {
const { t } = useLazyTranslation(['jwt', 'jsonFormat']);
const { t } = useI18n(['jwt', 'jsonFormat']);
const [jwtInput, setJwtInput] = useState('');
// 2. 防抖中转管道:切断高频键盘敲击时的红色语法闪烁
@@ -74,7 +74,7 @@ export default function Index() {
<TextInputArea
minRows={5}
maxRows={10}
placeholder={t('jwt:placeholder')}
placeholder={t('jwt_placeholder')}
value={jwtInput}
onChange={(val) => {
const cleaned = val.replace(/^Bearer\s*/i, '').trim();