feat(ui): full i18n (th/en) + highway stop search + real km list

i18n:
- LangProvider (client context) + cookie/lang localStorage sync
- locales/th.json + en.json จาก design (269 keys)
- แปล header/nav/footer/home/route/stop/check ผ่าน t()
- server pages อ่าน cookie lang (SSR แปลตรง) + client context

Stop search (หน้า /stops):
- code search 5 หลัก (kilometer '36+020' → pad5 '36020') + numpad
- place search (ชื่อสถานที่) + suggest
- near-me (geolocation → ป้ายทางหลวงใกล้สุด 8 อัน, haversine)
- data: busstop_list.json (154 ป้ายทางหลวง)

Route detail: km list ใช้ระยะจริงจาก stop-km.json (แทน stop_sequence)

Note: 'nearby ใกล้เคียงป้าย' ไม่ทำ — stations.json ไม่มี landmarks data
This commit is contained in:
phattaranun.a committed 2026-10-10 23:17:24 +07:00
1 parent 0c3936df69
commit 1526c5b6d0
18 files changed
+3146 -141

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import th from "@/data/locales/th.json";
import en from "@/data/locales/en.json";
export type Lang = "th" | "en";
const DICTS: Record<Lang, Record<string, string>> = {
th: th as Record<string, string>,
en: en as Record<string, string>,
};
/** แปลข้อความตามคีย์ (จาก design locales/th.json + en.json) */
export function t(
key: string,
lang: Lang,
vars?: Record<string, string | number>,
): string {
let s = DICTS[lang]?.[key] ?? DICTS.th[key] ?? key;
if (vars) {
for (const [k, v] of Object.entries(vars)) {
s = s.replace(new RegExp(`\\{${k}\\}`, "g"), String(v));
}
}
return s;
}
/** อ่าน lang จากคุกกี้ (server-side) */
export function langFromCookie(cookieHeader: string | null | undefined): Lang {
if (!cookieHeader) return "th";
const m = cookieHeader.match(/(?:^|;\s*)lang=(th|en)\b/);
return m ? (m[1] as Lang) : "th";
}