From f40485e2dc27e56da311ebedcd50169df0d657ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Wed, 27 May 2026 14:10:11 +0800 Subject: [PATCH] fix(ErrorBoundary): replace hardcoded Chinese with i18n via withTranslation HOC Use react-i18next withTranslation HOC for class component to translate title, description, and refresh button text. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- components/ErrorBoundary.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/components/ErrorBoundary.tsx b/components/ErrorBoundary.tsx index 3789b0e..c74e7a6 100644 --- a/components/ErrorBoundary.tsx +++ b/components/ErrorBoundary.tsx @@ -1,8 +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'; -interface Props { +interface Props extends WithTranslation { children: ReactNode; } @@ -11,10 +12,7 @@ interface State { error: Error | null; } -/** - * 错误边界组件:捕获子组件树中的 JavaScript 错误 - */ -export class ErrorBoundary extends Component { +class ErrorBoundaryBase extends Component { state: State = { hasError: false, error: null, @@ -39,6 +37,7 @@ export class ErrorBoundary extends Component { }; render() { + const { t } = this.props; if (this.state.hasError) { return (
@@ -46,10 +45,10 @@ export class ErrorBoundary extends Component {
-

糟糕,出了点问题

-

- 应用遇到了一些意外错误。您可以尝试刷新页面或重置应用。 -

+

+ {t('errorBoundary.title')} +

+

{t('errorBoundary.description')}

{this.state.error && (
@@ -63,7 +62,7 @@ export class ErrorBoundary extends Component {
               className="rounded-lg font-bold shadow-sm"
             >
               
-              刷新应用
+              {t('errorBoundary.refresh')}
             
           
@@ -74,4 +73,5 @@ export class ErrorBoundary extends Component { } } +export const ErrorBoundary = withTranslation('common')(ErrorBoundaryBase); export default ErrorBoundary;