"use client"; // Interface language in client components (PEP-98): the root layout passes the locale, // `useT()` gives a translator over the bundled dictionaries. import { createContext, useContext, useMemo, useTransition, type ReactNode } from "react"; import { useRouter } from "next/navigation"; import { LOCALE_LABELS, LOCALES, translator, type Locale, type Translator } from "@peppa/shared/i18n"; import { setLanguage } from "@/app/locale-actions"; import { cn } from "@/lib/utils"; const LocaleContext = createContext("ru"); export function I18nProvider({ locale, children }: { locale: Locale; children: ReactNode }) { return {children}; } export function useLocale(): Locale { return useContext(LocaleContext); } export function useT(): Translator { const locale = useLocale(); return useMemo(() => translator(locale), [locale]); } /** RU / EN / KZ: saves the cookie (and the user's choice when logged in), then re-renders. */ export function LanguageSwitcher({ className }: { className?: string }) { const current = useLocale(); const t = useT(); const router = useRouter(); const [pending, start] = useTransition(); return (
{LOCALES.map((l) => ( ))}
); }