- Add translation key 'userDoesNotHavePublicCalendars' to all locale files (en, fr, vi, ru)
- Update ErrorSnackbar to support translation keys in error messages with params
- Update getTempCalendarsListAsync to throw error with translation key format instead of hardcoded message
- Error message now displays user-friendly translated text: '{User Name} does not have public calendars'
This commit is contained in:
@@ -20,6 +20,36 @@ export function ErrorSnackbar({
|
||||
dispatch(type === "calendar" ? calendarClearError() : userClearError());
|
||||
};
|
||||
|
||||
const getErrorMessage = () => {
|
||||
if (!error) return t("error.unknown");
|
||||
|
||||
// Check if error message is a translation key with params
|
||||
// Format: TRANSLATION:key|param1=value1|param2=value2
|
||||
if (error.startsWith("TRANSLATION:")) {
|
||||
const parts = error.substring(12).split("|");
|
||||
const translationKey = parts[0];
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const equalIndex = parts[i].indexOf("=");
|
||||
if (equalIndex === -1) continue;
|
||||
const key = parts[i].substring(0, equalIndex);
|
||||
const value = parts[i].substring(equalIndex + 1);
|
||||
if (key && value) {
|
||||
try {
|
||||
params[key] = decodeURIComponent(value);
|
||||
} catch {
|
||||
params[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t(translationKey, params);
|
||||
}
|
||||
|
||||
return error;
|
||||
};
|
||||
|
||||
return (
|
||||
<Snackbar
|
||||
open={!!error}
|
||||
@@ -36,7 +66,7 @@ export function ErrorSnackbar({
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{error || t("error.unknown")}
|
||||
{getErrorMessage()}
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user