diff --git a/components/chat-message-display.tsx b/components/chat-message-display.tsx index 0a14597..44aa588 100644 --- a/components/chat-message-display.tsx +++ b/components/chat-message-display.tsx @@ -27,6 +27,7 @@ import { ReasoningTrigger, } from "@/components/ai-elements/reasoning" import { ScrollArea } from "@/components/ui/scroll-area" +import { useDictionary } from "@/hooks/use-dictionary" import { getApiEndpoint } from "@/lib/base-path" import { applyDiagramOperations, @@ -205,6 +206,7 @@ export function ChatMessageDisplay({ onEditMessage, status = "idle", }: ChatMessageDisplayProps) { + const dict = useDictionary() const { chartXML, loadDiagram: onDisplayChart } = useDiagram() const messagesEndRef = useRef(null) const previousXML = useRef("") @@ -268,9 +270,7 @@ export function ChatMessageDisplay({ setTimeout(() => setCopiedMessageId(null), 2000) } catch (fallbackErr) { console.error("Failed to copy message:", fallbackErr) - toast.error( - "Failed to copy message. Please copy manually or check clipboard permissions.", - ) + toast.error(dict.chat.failedToCopyDetail) setCopyFailedMessageId(messageId) setTimeout(() => setCopyFailedMessageId(null), 2000) } finally { @@ -304,7 +304,7 @@ export function ChatMessageDisplay({ }) } catch (error) { console.error("Failed to log feedback:", error) - toast.error("Failed to record your feedback. Please try again.") + toast.error(dict.errors.failedToRecordFeedback) // Revert optimistic UI update setFeedback((prev) => { const next = { ...prev } @@ -349,9 +349,7 @@ export function ChatMessageDisplay({ console.error( "[ChatMessageDisplay] Malformed XML detected in final output", ) - toast.error( - "AI generated invalid diagram XML. Please try regenerating.", - ) + toast.error(dict.errors.malformedXml) } return // Skip this update } @@ -402,9 +400,7 @@ export function ChatMessageDisplay({ "[ChatMessageDisplay] XML validation failed:", validation.error, ) - toast.error( - "Diagram validation failed. Please try regenerating.", - ) + toast.error(dict.errors.validationFailed) } } catch (error) { console.error( @@ -413,9 +409,7 @@ export function ChatMessageDisplay({ ) // Only show toast if this is the final XML (not during streaming) if (showToast) { - toast.error( - "Failed to process diagram. Please try regenerating.", - ) + toast.error(dict.errors.failedToProcess) } } } @@ -832,7 +826,10 @@ export function ChatMessageDisplay({ ) }} className="p-1.5 rounded-lg text-muted-foreground/60 hover:text-muted-foreground hover:bg-muted transition-colors" - title="Edit message" + title={ + dict.chat + .editMessage + } > @@ -849,11 +846,13 @@ export function ChatMessageDisplay({ title={ copiedMessageId === message.id - ? "Copied!" + ? dict.chat.copied : copyFailedMessageId === message.id - ? "Failed to copy" - : "Copy message" + ? dict.chat + .failedToCopy + : dict.chat + .copyResponse } > {copiedMessageId === @@ -968,7 +967,7 @@ export function ChatMessageDisplay({ }} className="px-3 py-1.5 text-xs rounded-lg bg-muted hover:bg-muted/80 transition-colors" > - Cancel + {dict.common.cancel} @@ -1123,7 +1122,8 @@ export function ChatMessageDisplay({ "user" && isLastUserMessage && onEditMessage - ? "Click to edit" + ? dict.chat + .clickToEdit : undefined } > @@ -1325,8 +1325,8 @@ export function ChatMessageDisplay({ title={ copiedMessageId === message.id - ? "Copied!" - : "Copy response" + ? dict.chat.copied + : dict.chat.copyResponse } > {copiedMessageId === @@ -1352,7 +1352,9 @@ export function ChatMessageDisplay({ ) } className="p-1.5 rounded-lg text-muted-foreground/60 hover:text-foreground hover:bg-muted transition-colors" - title="Regenerate response" + title={ + dict.chat.regenerate + } > @@ -1374,7 +1376,7 @@ export function ChatMessageDisplay({ ? "text-green-600 bg-green-100" : "text-muted-foreground/60 hover:text-green-600 hover:bg-green-50" }`} - title="Good response" + title={dict.chat.goodResponse} > @@ -1393,7 +1395,7 @@ export function ChatMessageDisplay({ ? "text-red-600 bg-red-100" : "text-muted-foreground/60 hover:text-red-600 hover:bg-red-50" }`} - title="Bad response" + title={dict.chat.badResponse} > diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index 114310b..cf04a2c 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -26,6 +26,7 @@ import { useDictionary } from "@/hooks/use-dictionary" import { getSelectedAIConfig, useModelConfig } from "@/hooks/use-model-config" import { getApiEndpoint } from "@/lib/base-path" import { findCachedResponse } from "@/lib/cached-responses" +import { formatMessage } from "@/lib/i18n/utils" import { isPdfFile, isTextFile } from "@/lib/pdf-utils" import { type FileData, useFileProcessor } from "@/lib/use-file-processor" import { useQuotaManager } from "@/lib/use-quota-manager" @@ -389,7 +390,9 @@ export default function ChatPanel({ MAX_CONTINUATION_RETRY_COUNT ) { toast.error( - `Continuation retry limit reached (${MAX_CONTINUATION_RETRY_COUNT}). The diagram may be too complex.`, + formatMessage(dict.errors.continuationRetryLimit, { + max: MAX_CONTINUATION_RETRY_COUNT, + }), ) continuationRetryCountRef.current = 0 partialXmlRef.current = "" @@ -400,7 +403,9 @@ export default function ChatPanel({ // Regular error: check retry count limit if (autoRetryCountRef.current >= MAX_AUTO_RETRY_COUNT) { toast.error( - `Auto-retry limit reached (${MAX_AUTO_RETRY_COUNT}). Please try again manually.`, + formatMessage(dict.errors.retryLimit, { + max: MAX_AUTO_RETRY_COUNT, + }), ) autoRetryCountRef.current = 0 partialXmlRef.current = "" @@ -450,7 +455,7 @@ export default function ChatPanel({ // On complete failure, clear storage to allow recovery localStorage.removeItem(STORAGE_MESSAGES_KEY) localStorage.removeItem(STORAGE_XML_SNAPSHOTS_KEY) - toast.error("Session data was corrupted. Starting fresh.") + toast.error(dict.errors.sessionCorrupted) } }, [setMessages]) @@ -651,12 +656,10 @@ export default function ChatPanel({ localStorage.removeItem(STORAGE_DIAGRAM_XML_KEY) localStorage.setItem(STORAGE_SESSION_ID_KEY, newSessionId) sessionStorage.removeItem(SESSION_STORAGE_INPUT_KEY) - toast.success("Started a fresh chat") + toast.success(dict.dialogs.clearSuccess) } catch (error) { console.error("Failed to clear localStorage:", error) - toast.warning( - "Chat cleared but browser storage could not be updated", - ) + toast.warning(dict.errors.storageUpdateFailed) } setShowNewChatDialog(false) @@ -889,7 +892,7 @@ export default function ChatPanel({ return (
- AI Chat + {dict.nav.aiChat}
) @@ -956,7 +959,7 @@ export default function ChatPanel({ rel="noopener noreferrer" className="text-sm text-muted-foreground hover:text-foreground transition-colors ml-2" > - About + {dict.nav.about} )} {!isMobile && ( @@ -966,7 +969,7 @@ export default function ChatPanel({ rel="noopener noreferrer" >
- Dev: XML Streaming Simulator + {dict.dev.title}