locale-provider.tsx 587 B

123456789101112131415161718192021222324
  1. "use client";
  2. import { createContext, use, type ReactNode } from "react";
  3. import type { Locale } from "@/lib/i18n";
  4. import { messages } from "@/messages";
  5. const LocaleContext = createContext<Locale>("en");
  6. /** Hands the page's language to client components. */
  7. export function LocaleProvider({
  8. lang,
  9. children,
  10. }: {
  11. lang: Locale;
  12. children: ReactNode;
  13. }) {
  14. return <LocaleContext value={lang}>{children}</LocaleContext>;
  15. }
  16. export const useLocale = () => use(LocaleContext);
  17. /** The strings for the page's language. */
  18. export const useT = () => messages[use(LocaleContext)];