fix(i18n): localize API error messages by code (no more raw English)

Error toasts surfaced the raw English backend message. Added an errors namespace (fa/ar/en) keyed by error code + a useApiError() resolver that maps ApiClientError.code to the localized message (fallback to a localized generic). Wired into menu, tables, demo banner, and subscription checkout; hardened getErrorMessage so it never returns the raw backend message.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-02 00:04:48 +03:30
parent 7519f474f3
commit 75d5bbc84a
9 changed files with 123 additions and 19 deletions
@@ -7,6 +7,7 @@ import * as signalR from "@microsoft/signalr";
import { Plus, QrCode, Pencil, Video, Trash2, Copy, ExternalLink } from "lucide-react";
import { DemoDataBanner } from "@/components/demo/demo-data-banner";
import { notify } from "@/lib/notify";
import { useApiError } from "@/lib/use-api-error";
import { MediaPairUpload } from "@/components/media/media-pair-upload";
import { PageHeader } from "@/components/layout/page-header";
import {
@@ -53,6 +54,7 @@ export function TablesScreen() {
const branchId = useBranchStore((s) => s.branchId);
const queryClient = useQueryClient();
const confirmDialog = useConfirm();
const apiError = useApiError();
const [actionMessage, setActionMessage] = useState<string | null>(null);
const [showForm, setShowForm] = useState(false);
const [number, setNumber] = useState("");
@@ -123,7 +125,7 @@ export function TablesScreen() {
refresh();
},
onError: (err) => {
const msg = err instanceof ApiClientError ? err.message : t("createError");
const msg = apiError(err, t("createError"));
setActionMessage(msg);
notify.error(msg);
},
@@ -142,7 +144,7 @@ export function TablesScreen() {
refresh();
},
onError: (err) => {
setActionMessage(err instanceof ApiClientError ? err.message : t("cleaningError"));
setActionMessage(apiError(err, t("cleaningError")));
},
});
@@ -158,7 +160,7 @@ export function TablesScreen() {
setActionMessage(t("tableHasOpenOrder"));
return;
}
setActionMessage(err instanceof ApiClientError ? err.message : t("deleteError"));
setActionMessage(apiError(err, t("deleteError")));
},
});
@@ -188,7 +190,7 @@ export function TablesScreen() {
refresh();
},
onError: (err) => {
const msg = err instanceof ApiClientError ? err.message : t("createError");
const msg = apiError(err, t("createError"));
setActionMessage(msg);
notify.error(msg);
},