(key: keyof Translation, locale: string, params?: Record<string, string>)
| 1370 | }; |
| 1371 | |
| 1372 | export function t(key: keyof Translation, locale: string, params?: Record<string, string>): string { |
| 1373 | let text: string; |
| 1374 | |
| 1375 | // Try specific locale match first |
| 1376 | if (I18N[locale] && I18N[locale][key]) { |
| 1377 | text = I18N[locale][key]; |
| 1378 | } else if (locale === 'es-419') { |
| 1379 | // Fallback logic |
| 1380 | text = I18N['es-ES'][key] || en[key]; |
| 1381 | } else if (locale === 'pt-PT') { |
| 1382 | text = I18N['pt-BR'][key] || en[key]; |
| 1383 | } else { |
| 1384 | // Default fallback to English |
| 1385 | text = en[key] || key; |
| 1386 | } |
| 1387 | |
| 1388 | // Replace {{xx}} placeholders with params |
| 1389 | if (params) { |
| 1390 | text = text.replace(/\{\{(\w+)\}\}/g, (_, key) => params[key] ?? `{{${key}}}`); |
| 1391 | } |
| 1392 | |
| 1393 | return text; |
| 1394 | } |
| 1395 |
no outgoing calls
no test coverage detected