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
+7 -8
View File
@@ -1,9 +1,9 @@
import { Component, ErrorInfo, ReactNode } from 'react';
import { withTranslation, type WithTranslation } from 'react-i18next';
import { AlertCircle, RefreshCw } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { getMessage } from '@/utils/chromeI18n';
interface Props extends WithTranslation {
interface Props {
children: ReactNode;
resetKey?: string | number;
}
@@ -13,7 +13,7 @@ interface State {
error: Error | null;
}
class PageErrorBoundaryBase extends Component<Props, State> {
class PageErrorBoundary extends Component<Props, State> {
state: State = {
hasError: false,
error: null,
@@ -38,7 +38,6 @@ class PageErrorBoundaryBase extends Component<Props, State> {
};
render() {
const { t } = this.props;
if (this.state.hasError) {
return (
<div className="flex flex-col items-center justify-center flex-1 p-6 min-h-[300px] animate-in fade-in zoom-in-95 duration-200">
@@ -48,10 +47,10 @@ class PageErrorBoundaryBase extends Component<Props, State> {
</div>
<h3 className="text-base font-semibold text-foreground mb-1.5">
{t('pageErrorBoundary.title')}
{getMessage('pageErrorBoundary_title')}
</h3>
<p className="text-xs text-muted-foreground mb-5">
{t('pageErrorBoundary.description')}
{getMessage('pageErrorBoundary_description')}
</p>
{this.state.error && (
@@ -69,7 +68,7 @@ class PageErrorBoundaryBase extends Component<Props, State> {
className="font-medium shadow-sm"
>
<RefreshCw className="mr-1.5 h-3.5 w-3.5" />
{t('errorBoundary.retry')}
{getMessage('errorBoundary_retry')}
</Button>
</div>
</div>
@@ -80,5 +79,5 @@ class PageErrorBoundaryBase extends Component<Props, State> {
}
}
export const PageErrorBoundary = withTranslation('common')(PageErrorBoundaryBase);
export { PageErrorBoundary };
export default PageErrorBoundary;