/** * Error Boundary Component * Catches React errors and displays fallback UI * Note: Class components can't use hooks, so we accept translations as props */ import { Component, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; name?: string; } interface State { hasError: boolean; error: Error | null; } // Default messages (will be in English as fallback) const defaultMessages = { failed: 'failed to load', unknownError: 'Unknown error', retry: 'Retry', }; export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { console.error(`[ErrorBoundary${this.props.name ? `: ${this.props.name}` : ''}]`, error, errorInfo); } render(): ReactNode { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

{this.props.name || 'Component'} {defaultMessages.failed}

{this.state.error?.message || defaultMessages.unknownError}

); } return this.props.children; } }