/** * Utilities for class components * Provides common functionality that class components need */ import { en } from '@/locales/en.ts'; /** * Minimal translation helper for class components * Since class components can't use hooks, this provides basic translation support * using English as fallback when full i18n context isn't available */ export const classComponentT = ( key: string, replacements?: { [key: string]: string | number } ): string => { const path = key.split('.'); let result: unknown = en; for (const p of path) { if (result && typeof result === 'object' && p in result) { result = (result as Record)[p]; } else { return key; // Return key if path not found } } if (typeof result === 'string' && replacements) { let translated = result; Object.keys(replacements).forEach((placeholder) => { const regex = new RegExp(`{{${placeholder}}}`, 'g'); translated = translated.replace(regex, String(replacements[placeholder])); }); return translated; } return typeof result === 'string' ? result : key; };