diff --git a/frontend/src/hooks/useReasoningTranslation.ts b/frontend/src/hooks/useReasoningTranslation.ts index 8161b5e2..119b2840 100644 --- a/frontend/src/hooks/useReasoningTranslation.ts +++ b/frontend/src/hooks/useReasoningTranslation.ts @@ -34,7 +34,8 @@ export function useReasoningTranslation() { return t('purchaseOrder.low_stock_detection', { supplier_name: 'Unknown', product_names_joined: 'Items', - days_until_stockout: 7 + days_until_stockout: 7, + defaultValue: 'Purchase order required for inventory replenishment' }); } @@ -45,10 +46,11 @@ export function useReasoningTranslation() { ...parameters, product_names_joined: Array.isArray(parameters.product_names) ? parameters.product_names.join(', ') - : parameters.product_names || 'Items' + : parameters.product_names || 'Items', + defaultValue: `Purchase order: ${type}` }; - return t(`purchaseOrder.${type}`, params); + return t(`purchaseOrder.${type}`, params) || `Purchase order: ${type}`; }; /** @@ -60,12 +62,17 @@ export function useReasoningTranslation() { product_name: 'Product', predicted_demand: 0, current_stock: 0, - confidence_score: 85 + confidence_score: 85, + defaultValue: 'Production batch scheduled based on demand forecast' }); } const { type, parameters } = reasoningData; - return t(`productionBatch.${type}`, parameters); + const params = { + ...parameters, + defaultValue: `Production batch: ${type}` + }; + return t(`productionBatch.${type}`, params) || `Production batch: ${type}`; }; /** @@ -80,10 +87,11 @@ export function useReasoningTranslation() { ...consequenceData, affected_products_joined: Array.isArray(consequenceData.affected_products) ? consequenceData.affected_products.join(', ') - : consequenceData.affected_products || 'products' + : consequenceData.affected_products || 'products', + defaultValue: `Impact: ${consequenceData.type}` }; - return t(`consequence.${consequenceData.type}`, params); + return t(`consequence.${consequenceData.type}`, params) || ''; }; /** @@ -91,7 +99,7 @@ export function useReasoningTranslation() { */ const translateSeverity = (severity?: string): string => { if (!severity) return ''; - return t(`severity.${severity}`); + return t(`severity.${severity}`, { defaultValue: severity }) || ''; }; /** @@ -99,7 +107,7 @@ export function useReasoningTranslation() { */ const translateTrigger = (trigger?: string): string => { if (!trigger) return ''; - return t(`triggers.${trigger}`); + return t(`triggers.${trigger}`, { defaultValue: trigger }) || ''; }; /** diff --git a/frontend/src/pages/app/analytics/ai-insights/AIInsightsPage.tsx b/frontend/src/pages/app/analytics/ai-insights/AIInsightsPage.tsx index c6f8da73..3b22aa90 100644 --- a/frontend/src/pages/app/analytics/ai-insights/AIInsightsPage.tsx +++ b/frontend/src/pages/app/analytics/ai-insights/AIInsightsPage.tsx @@ -137,13 +137,18 @@ const AIInsightsPage: React.FC = () => { } try { - return t(`${category}.${insight.reasoning_data.type}`, insight.reasoning_data.parameters); + const params = { + ...insight.reasoning_data.parameters, + defaultValue: insight.description || `${category}: ${insight.reasoning_data.type}` + }; + const translated = t(`${category}.${insight.reasoning_data.type}`, params); + return translated || insight.description || `AI Insight: ${insight.reasoning_data.type}`; } catch (e) { // Fall back to description if translation key not found - return insight.description; + return insight.description || 'AI Insight'; } } - return insight.description; + return insight.description || 'AI Insight'; }; return (