- Complete Next.js 16 app with App Router: Home, About, Products, Contact, Privacy pages - Product detail pages: ZappCare, Unified TMS, EMR Clinic - Bilingual support (Indonesian/English) via LanguageContext + translations.ts - Language switcher pill button (🇮🇩 ID / 🇬🇧 EN) in Navbar with localStorage persistence - Navbar with logo, responsive mobile menu, translated nav links - Contact form with captcha, server action email sending, translated labels - Material Design 3 color tokens, Manrope + Inter fonts, Material Symbols icons - Local product image assets and company logo Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
832 B
TypeScript
33 lines
832 B
TypeScript
"use client";
|
|
|
|
import { createContext, useContext, useState, useEffect } from "react";
|
|
|
|
export type Lang = "id" | "en";
|
|
|
|
const LanguageContext = createContext<{
|
|
lang: Lang;
|
|
setLang: (l: Lang) => void;
|
|
}>({ lang: "id", setLang: () => {} });
|
|
|
|
export function LanguageProvider({ children }: { children: React.ReactNode }) {
|
|
const [lang, setLangState] = useState<Lang>("id");
|
|
|
|
useEffect(() => {
|
|
const stored = localStorage.getItem("iptek-lang") as Lang | null;
|
|
if (stored === "id" || stored === "en") setLangState(stored);
|
|
}, []);
|
|
|
|
const setLang = (l: Lang) => {
|
|
setLangState(l);
|
|
localStorage.setItem("iptek-lang", l);
|
|
};
|
|
|
|
return (
|
|
<LanguageContext.Provider value={{ lang, setLang }}>
|
|
{children}
|
|
</LanguageContext.Provider>
|
|
);
|
|
}
|
|
|
|
export const useLang = () => useContext(LanguageContext);
|