fix(i18n): ErrorBoundary 组件全量国际化 + 清理 unused import 回归
- 删除 ErrorBoundary.tsx 中未使用的 useTranslation import(unused-vars 回归 1→0) - 国际化 5 处硬编码 UI 文案(页面出现错误/描述/查看详情/返回首页/复制错误) - 国际化错误报告模板(错误报告/时间/用户代理/错误信息/组件堆栈) - 新增 10 个 common.eb* 翻译键(zh-CN/en-US 完全对齐,6182/6182) - 翻译键总数 3638 → 3648,零丢失 - tsc -b=0, npm build ✓ (21.77s), ESLint unused=0/any=37
This commit is contained in:
1 parent
76393c663c
commit
88122a72a2
3 files changed
+958
-939
No files matched your search
@@ -2,7 +2,6 @@ import { Component, type ErrorInfo, type ReactNode } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertTriangle, RotateCcw, Home, Bug } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
interface Props {
|
||||
@@ -48,7 +47,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
|
||||
handleReport = () => {
|
||||
const { error, errorInfo } = this.state;
|
||||
const body = `## 错误报告\n\n**时间:** ${new Date().toISOString()}\n**URL:** ${window.location.href}\n**用户代理:** ${navigator.userAgent}\n\n### 错误信息\n\n\`\`\`\n${error?.name}: ${error?.message}\n\`\`\`\n\n### 组件堆栈\n\n\`\`\`\n${errorInfo?.componentStack}\n\`\`\`\n`;
|
||||
const body = `## ${i18n.t('common.ebReportTitle')}\n\n**${i18n.t('common.ebReportTime')}:** ${new Date().toISOString()}\n**URL:** ${window.location.href}\n**${i18n.t('common.ebReportUA')}:** ${navigator.userAgent}\n\n### ${i18n.t('common.ebReportErrorMsg')}\n\n\`\`\`\n${error?.name}: ${error?.message}\n\`\`\`\n\n### ${i18n.t('common.ebReportStack')}\n\n\`\`\`\n${errorInfo?.componentStack}\n\`\`\`\n`;
|
||||
navigator.clipboard.writeText(body).then(() => {
|
||||
toast.success(i18n.t('common.errorCopiedToClipboard'));
|
||||
}).catch(() => {
|
||||
@@ -73,10 +72,10 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
{/* Title */}
|
||||
<div>
|
||||
<h2 className="text-xl font-bold text-[var(--dg-text-primary)]">
|
||||
页面出现错误
|
||||
{i18n.t('common.ebPageError')}
|
||||
</h2>
|
||||
<p className="text-sm text-[var(--dg-text-muted)] mt-2">
|
||||
抱歉,该页面遇到了意外错误。您可以尝试重新加载或返回首页。
|
||||
{i18n.t('common.ebDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -86,7 +85,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
<details className="group">
|
||||
<summary className="cursor-pointer text-xs text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)] transition-colors flex items-center gap-1.5">
|
||||
<Bug className="h-3.5 w-3.5" />
|
||||
查看错误详情
|
||||
{i18n.t('common.ebViewDetails')}
|
||||
</summary>
|
||||
<div className="mt-2 p-3 rounded-lg bg-[var(--dg-bg-tertiary)] border border-[var(--dg-border)] overflow-auto max-h-48">
|
||||
<code className="text-xs dg-text-red font-mono block whitespace-pre-wrap">
|
||||
@@ -110,7 +109,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
onClick={this.handleGoHome}
|
||||
>
|
||||
<Home className="h-4 w-4 mr-1.5" />
|
||||
返回首页
|
||||
{i18n.t('common.ebGoHome')}
|
||||
</Button>
|
||||
<Button
|
||||
className="dg-btn-primary"
|
||||
@@ -125,7 +124,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
onClick={this.handleReport}
|
||||
>
|
||||
<Bug className="h-4 w-4 mr-1.5" />
|
||||
复制错误
|
||||
{i18n.t('common.ebCopyError')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user