From 0908358f978f238129ec3c329763367cc96a21e5 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:08:10 +0800 Subject: [PATCH] fix(CopyButton): replace hardcoded Chinese strings with i18n t() calls Use useTranslation('common') for tooltip, copy empty/success/error toast messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- components/CopyButton.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/CopyButton.tsx b/components/CopyButton.tsx index cf06fce..99570de 100644 --- a/components/CopyButton.tsx +++ b/components/CopyButton.tsx @@ -4,6 +4,7 @@ import { copyTextToClipboard } from '@/utils/clipboard'; import { cn } from '@/lib/utils'; import { buttonVariants, type ButtonProps } from '@/components/ui/button'; import { toast } from 'sonner'; +import { useTranslation } from 'react-i18next'; interface CopyButtonProps extends Omit { text: string; @@ -12,12 +13,13 @@ interface CopyButtonProps extends Omit { export const CopyButton: React.FC = ({ text, - tooltip = '复制', + tooltip, variant = 'ghost', size = 'sm', className, ...props }) => { + const { t } = useTranslation('common'); const [copied, setCopied] = useState(false); const timerRef = useRef | null>(null); @@ -31,18 +33,18 @@ export const CopyButton: React.FC = ({ e.stopPropagation(); if (!text) { - toast.error('无内容可复制'); + toast.error(t('messages.copyEmpty')); return; } const success = await copyTextToClipboard(text); if (success) { - toast.success('复制成功'); + toast.success(t('messages.copySuccess')); setCopied(true); if (timerRef.current) clearTimeout(timerRef.current); timerRef.current = setTimeout(() => setCopied(false), 1500); } else { - toast.error('复制失败'); + toast.error(t('messages.copyError')); } }; @@ -50,7 +52,7 @@ export const CopyButton: React.FC = ({