- 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());
|
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 (
|
return (
|
||||||
<Snackbar
|
<Snackbar
|
||||||
open={!!error}
|
open={!!error}
|
||||||
@@ -36,7 +66,7 @@ export function ErrorSnackbar({
|
|||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{error || t("error.unknown")}
|
{getErrorMessage()}
|
||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -170,7 +170,16 @@ export const getTempCalendarsListAsync = createAsyncThunk<
|
|||||||
tempUser.openpaasId ?? "",
|
tempUser.openpaasId ?? "",
|
||||||
"sharedPublic=true&"
|
"sharedPublic=true&"
|
||||||
)) as Record<string, any>;
|
)) as Record<string, any>;
|
||||||
const rawCalendars = calendars._embedded["dav:calendar"];
|
|
||||||
|
const rawCalendars = calendars._embedded?.["dav:calendar"];
|
||||||
|
if (!rawCalendars || rawCalendars.length === 0) {
|
||||||
|
const userName = tempUser.displayName || tempUser.email || "User";
|
||||||
|
// Format: TRANSLATION:key|param1=value1
|
||||||
|
const encodedName = encodeURIComponent(userName);
|
||||||
|
throw new Error(
|
||||||
|
`TRANSLATION:calendar.userDoesNotHavePublicCalendars|name=${encodedName}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const cal of rawCalendars) {
|
for (const cal of rawCalendars) {
|
||||||
const name = cal["dav:name"];
|
const name = cal["dav:name"];
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"browseOtherCalendars": "Browse other calendars",
|
"browseOtherCalendars": "Browse other calendars",
|
||||||
"noPublicCalendarsFor": "No publicly available calendars for %{name}",
|
"noPublicCalendarsFor": "No publicly available calendars for %{name}",
|
||||||
"noMoreCalendarsFor": "No more calendars for %{name}",
|
"noMoreCalendarsFor": "No more calendars for %{name}",
|
||||||
|
"userDoesNotHavePublicCalendars": "%{name} does not have public calendars",
|
||||||
"delete": {
|
"delete": {
|
||||||
"title": "Remove %{name}?",
|
"title": "Remove %{name}?",
|
||||||
"personalWarning": "You will lose all events in this calendar.",
|
"personalWarning": "You will lose all events in this calendar.",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"browseOtherCalendars": "Parcourir d'autres calendriers",
|
"browseOtherCalendars": "Parcourir d'autres calendriers",
|
||||||
"noPublicCalendarsFor": "Aucun calendrier public disponible pour %{name}",
|
"noPublicCalendarsFor": "Aucun calendrier public disponible pour %{name}",
|
||||||
"noMoreCalendarsFor": "Plus de calendriers disponibles pour %{name}",
|
"noMoreCalendarsFor": "Plus de calendriers disponibles pour %{name}",
|
||||||
|
"userDoesNotHavePublicCalendars": "%{name} n'a pas de calendriers publics",
|
||||||
"delete": {
|
"delete": {
|
||||||
"title": "Supprimer %{name} ?",
|
"title": "Supprimer %{name} ?",
|
||||||
"personalWarning": "Vous allez perdre tous les événements de ce calendrier.",
|
"personalWarning": "Vous allez perdre tous les événements de ce calendrier.",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"browseOtherCalendars": "Просмотреть другие календари",
|
"browseOtherCalendars": "Просмотреть другие календари",
|
||||||
"noPublicCalendarsFor": "Нет общедоступных календарей для %{name}",
|
"noPublicCalendarsFor": "Нет общедоступных календарей для %{name}",
|
||||||
"noMoreCalendarsFor": "Других календарей для %{name} нет",
|
"noMoreCalendarsFor": "Других календарей для %{name} нет",
|
||||||
|
"userDoesNotHavePublicCalendars": "%{name} не имеет общедоступных календарей",
|
||||||
"delete": {
|
"delete": {
|
||||||
"title": "Удалить %{name}?",
|
"title": "Удалить %{name}?",
|
||||||
"personalWarning": "Вы потеряете все события в этом календаре.",
|
"personalWarning": "Вы потеряете все события в этом календаре.",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"browseOtherCalendars": "Xem các lịch khác",
|
"browseOtherCalendars": "Xem các lịch khác",
|
||||||
"noPublicCalendarsFor": "Không có lịch công khai cho %{name}",
|
"noPublicCalendarsFor": "Không có lịch công khai cho %{name}",
|
||||||
"noMoreCalendarsFor": "Không còn lịch nào cho %{name}",
|
"noMoreCalendarsFor": "Không còn lịch nào cho %{name}",
|
||||||
|
"userDoesNotHavePublicCalendars": "%{name} không có lịch công khai",
|
||||||
"delete": {
|
"delete": {
|
||||||
"title": "Xóa %{name}?",
|
"title": "Xóa %{name}?",
|
||||||
"personalWarning": "Bạn sẽ mất tất cả sự kiện trong lịch này.",
|
"personalWarning": "Bạn sẽ mất tất cả sự kiện trong lịch này.",
|
||||||
|
|||||||
Reference in New Issue
Block a user