Merged in feature/refactor-lang (pull request #387)
feat: SW-238 Avoid prop drilling of lang Approved-by: Michael Zetterberg
This commit is contained in:
22
i18n/serverContext.ts
Normal file
22
i18n/serverContext.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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 const setLang = (newLang: Lang) => {
|
||||
getRef().current = newLang
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global language set for the current request
|
||||
*/
|
||||
export const getLang = () => getRef().current
|
||||
Reference in New Issue
Block a user