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
+3 -3
View File
@@ -28,7 +28,7 @@ import {
} from '@/config/features';
import GlobalSnackbar, { useSnackbarState } from '@/components/GlobalSnackbar';
import PageErrorBoundary from '@/components/PageErrorBoundary';
import { useTranslation } from 'react-i18next';
import { useI18n } from '@/utils/chromeI18n';
const PALETTE_COLORS: Record<PaletteColorKey, string> = {
primary: '#1976d2',
@@ -66,7 +66,7 @@ function SortableFeatureRow({
isDisabled,
onToggle,
}: SortableFeatureRowProps) {
const { t } = useTranslation(['features']);
const { t } = useI18n(['features']);
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
id: pageKey,
});
@@ -154,7 +154,7 @@ function SortableFeatureRow({
}
export default function App() {
const { t } = useTranslation(['features', 'common']);
const { t } = useI18n(['features', 'common']);
const initialWindowType = useMemo(() => {
if (typeof window === 'undefined') return 'popup';
+5 -12
View File
@@ -7,6 +7,7 @@ import {
getDefaultPageOrder,
getFeatureByKey,
} from '@/config/features';
import { getMessage } from '@/utils/chromeI18n';
// Mock storageUtil
vi.mock('@/utils/chromeStorage', () => ({
@@ -16,14 +17,6 @@ vi.mock('@/utils/chromeStorage', () => ({
},
}));
// Mock i18next
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string) => key,
}),
withTranslation: () => (Component: any) => Component,
}));
describe('Options App', () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -47,7 +40,7 @@ describe('Options App', () => {
for (const key of defaultOrder) {
const feature = getFeatureByKey(key);
if (feature) {
expect(screen.getByText(feature.labelKey)).toBeInTheDocument();
expect(screen.getByText(getMessage(feature.labelKey))).toBeInTheDocument();
}
}
});
@@ -72,7 +65,7 @@ describe('Options App', () => {
for (const key of defaultVisible) {
const feature = getFeatureByKey(key);
if (feature && key !== 'dashboard') {
expect(screen.getByText(feature.labelKey)).toBeInTheDocument();
expect(screen.getByText(getMessage(feature.labelKey))).toBeInTheDocument();
}
}
});
@@ -97,7 +90,7 @@ describe('Options App', () => {
for (const key of defaultOrder) {
const feature = getFeatureByKey(key);
if (feature) {
expect(screen.getByText(feature.labelKey)).toBeInTheDocument();
expect(screen.getByText(getMessage(feature.labelKey))).toBeInTheDocument();
}
}
});
@@ -125,7 +118,7 @@ describe('Options App', () => {
for (const key of defaultOrder) {
const feature = getFeatureByKey(key);
if (feature) {
expect(screen.getByText(feature.labelKey)).toBeInTheDocument();
expect(screen.getByText(getMessage(feature.labelKey))).toBeInTheDocument();
}
}
});
-1
View File
@@ -1,6 +1,5 @@
import ReactDOM from 'react-dom/client';
import AppRoot from '@/providers/AppRoot';
import '@/i18n';
import '@/src/index.css';
import App from './App';