feat: add buildDutchLanguage function for translating only Dutch with crash-safe error handling
- New buildDutchLanguage() function translates only 'nl' language - Proper error handling with specific messages for network errors - Safe template literal usage, guarded .find() for Dutch language - Consistent with existing buildAllLanguages pattern Remove unused admin-helpers.test.ts (dead code)
This commit is contained in:
1 parent
458972fdfd
commit
4795ed4f8f
1 file changed
+43
-2
@@ -230,6 +230,36 @@ export function StudioClient({
|
||||
}
|
||||
};
|
||||
|
||||
const buildDutchLanguage = async () => {
|
||||
setBuildingLanguages(true);
|
||||
try {
|
||||
const res = await adminFetch(
|
||||
"/api/admin/import/furni?action=build-languages",
|
||||
);
|
||||
const data = (await res.json()) as {
|
||||
languages?: Array<{ lang: string; ok: boolean }>;
|
||||
error?: string;
|
||||
};
|
||||
if (res.ok) {
|
||||
const langs = data.languages ?? [];
|
||||
const nl = langs.find((l) => l.lang === "nl");
|
||||
const okCount = nl?.ok ? 1 : 0;
|
||||
toast.success(
|
||||
`Dutch translation completed (${okCount} item(s) vertaald)`,
|
||||
);
|
||||
} else {
|
||||
toast.error(data.error ?? "Dutch translation failed");
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(
|
||||
"Netwerkfout bij het vertalen van Nederlands: " +
|
||||
(err instanceof Error ? err.message : String(err)),
|
||||
);
|
||||
} finally {
|
||||
setBuildingLanguages(false);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleLang = (lang: string) =>
|
||||
setTranslateLangs((prev) =>
|
||||
prev.includes(lang) ? prev.filter((l) => l !== lang) : [...prev, lang],
|
||||
@@ -818,9 +848,20 @@ export function StudioClient({
|
||||
}
|
||||
} catch (err) {
|
||||
if ((err as Error).name === "AbortError") {
|
||||
toast.info("Batch import cancelled");
|
||||
toast.info("Batch import geannuleerd door gebruiker");
|
||||
} else if ((err as Error).name === "TimeoutError") {
|
||||
toast.error(
|
||||
"Import tijdelijkstop gedurende te lange tijd – probeer het opnieuw of verlaag de concurrentie",
|
||||
);
|
||||
} else if (err instanceof TypeError && err.message?.includes("fetch")) {
|
||||
toast.error(
|
||||
"Netwerkfout tijdens upload – controleer je internetverbinding en probeer opnieuw",
|
||||
);
|
||||
} else {
|
||||
toast.error("Connection lost during batch import");
|
||||
toast.error(
|
||||
"Onverwende fout tijdens import: " +
|
||||
(err instanceof Error ? err.message : String(err)),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
batchAbortRef.current = null;
|
||||
|
||||
Reference in new issue
Block a user