feat(i18n) : add personal languages and compact weapon exports
CI / Verify (push) Successful in 1m18s
CI / Build immutable images and deploy (push) Successful in 1m57s

This commit is contained in:
2026-09-14 16:44:44 +07:00 Unverified
parent f214d330f0
commit e0794822b1
72 changed files with 4199 additions and 1011 deletions
+11 -8
View File
@@ -1,5 +1,6 @@
"use client";
import { useTranslation } from "@/components/i18n/locale-provider";
import { useEffect, useEffectEvent, useRef, useState } from "react";
import { toast } from "sonner";
@@ -36,6 +37,8 @@ export function useAutosave<Value, Draft = Value>({
parseLocalDraft?: (value: unknown) => Draft | null;
restoreLocalDraft?: (draft: Draft) => void;
}) {
const { t: translateMessage } = useTranslation();
const t = useEffectEvent(translateMessage);
const fingerprint = JSON.stringify(value);
const draftFingerprint = JSON.stringify(localDraft ?? value);
const [savedFingerprint, setSavedFingerprint] = useState(fingerprint);
@@ -81,19 +84,19 @@ export function useAutosave<Value, Draft = Value>({
else window.localStorage.removeItem(storageKey);
setHydrated(true);
};
toast("พบ Local draft ต้องการกู้คืนหรือไม่?", {
toast(t("พบ Local draft ต้องการกู้คืนหรือไม่?"), {
id: `restore:${storageKey}`,
description: "หากไม่เลือก ระบบจะใช้ข้อมูลล่าสุดจากเซิร์ฟเวอร์",
description: t("หากไม่เลือก ระบบจะใช้ข้อมูลล่าสุดจากเซิร์ฟเวอร์"),
duration: 10_000,
action: { label: "กู้คืน", onClick: () => finish(true) },
cancel: { label: "ไม่ใช้", onClick: () => finish(false) },
action: { label: t("กู้คืน"), onClick: () => finish(true) },
cancel: { label: t("ไม่ใช้"), onClick: () => finish(false) },
onDismiss: () => finish(false),
onAutoClose: () => finish(false),
});
} catch {
if (!storageWarningShown.current) {
storageWarningShown.current = true;
toast.error("ไม่สามารถเปิด Local draft ได้");
toast.error(t("ไม่สามารถเปิด Local draft ได้"));
}
setHydrated(true);
}
@@ -112,7 +115,7 @@ export function useAutosave<Value, Draft = Value>({
} catch {
if (!storageWarningShown.current) {
storageWarningShown.current = true;
toast.error("บันทึก Local draft ไม่สำเร็จ กรุณาตรวจสอบพื้นที่ของเบราว์เซอร์");
toast.error(t("บันทึก Local draft ไม่สำเร็จ กรุณาตรวจสอบพื้นที่ของเบราว์เซอร์"));
}
}
}, [draftFingerprint, hydrated, localDraft, savedDraftFingerprint, storageKey, version]);
@@ -127,7 +130,7 @@ export function useAutosave<Value, Draft = Value>({
if (result.status === "error" || result.status === "conflict") {
if (result.currentVersion) setVersion(result.currentVersion);
setErrorFingerprint(snapshotFingerprint);
toast.error(result.message ?? "บันทึกอัตโนมัติไม่สำเร็จ");
toast.error(t(result.message ?? "บันทึกอัตโนมัติไม่สำเร็จ"));
return;
}
if (result.version) setVersion(result.version);
@@ -135,7 +138,7 @@ export function useAutosave<Value, Draft = Value>({
setSavedDraftFingerprint(snapshotDraftFingerprint);
} catch (cause) {
setErrorFingerprint(snapshotFingerprint);
toast.error(cause instanceof Error ? cause.message : "บันทึกอัตโนมัติไม่สำเร็จ");
toast.error(t(cause instanceof Error ? cause.message : "บันทึกอัตโนมัติไม่สำเร็จ"));
} finally {
setSaving(false);
}