Files
web/i18n/serverContext.ts
2024-09-24 09:47:31 +02:00

25 lines
479 B
TypeScript

import { cache } from "react"
import { Lang } from "@/constants/languages"
const getRef = cache(() => ({ current: Lang.en }))
/**
* Set the language for the current request
*
* It works kind of like React's context,
* but on the server side, per request.
*
* @param newLang
*/
export function setLang(newLang: Lang) {
getRef().current = newLang
}
/**
* Get the global language set for the current request
*/
export function getLang() {
return getRef().current
}