mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-12 12:39:52 +08:00
30 lines
691 B
TypeScript
30 lines
691 B
TypeScript
"use client"
|
|||
|
|
|
||
|
|
import { createContext, useContext } from "react"
|
||
|
|
import type { Locale } from "@/lib/i18n/config"
|
||
|
|
|
||
|
|
const LocaleContext = createContext<Locale | null>(null)
|
||
|
|
|
||
|
|
/** The page's language; the web layout feeds it from its route param */
|
||
|
|
export function LocaleProvider({
|
||
|
|
locale,
|
||
|
|
children,
|
||
|
|
}: {
|
||
|
|
locale: Locale
|
||
|
|
children: React.ReactNode
|
||
|
|
}) {
|
||
|
|
return (
|
||
|
|
<LocaleContext.Provider value={locale}>
|
||
|
|
{children}
|
||
|
|
</LocaleContext.Provider>
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useLocale(): Locale {
|
||
|
|
const locale = useContext(LocaleContext)
|
||
|
|
if (!locale) {
|
||
|
|
throw new Error("useLocale must be used within a LocaleProvider")
|
||
|
|
}
|
||
|
|
return locale
|
||
|
|
}
|