16 lines
529 B
TypeScript
16 lines
529 B
TypeScript
/**
|
|
* Utility function to safely access translations with fallbacks
|
|
*/
|
|
export function safeTranslation(t: any, key: string, fallback: string = '') {
|
|
try {
|
|
const translation = t(key);
|
|
// If the translation returns the key itself or contains "MISSING", use fallback
|
|
if (translation === key || translation.includes('MISSING')) {
|
|
return fallback;
|
|
}
|
|
return translation;
|
|
} catch (error) {
|
|
console.warn(`Translation error for key "${key}":`, error);
|
|
return fallback;
|
|
}
|
|
} |