* move setLang() to a root layout
* fix: findLang only returns acceptable languages * fix: fallback to use header x-lang if we haven't setLang yet * fix: languageSchema, allow uppercase Approved-by: Linus Flood
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
"use client"
|
||||
import { useParams } from "next/navigation"
|
||||
|
||||
import { LangParams } from "@/types/params"
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
import { languageSchema } from "@/utils/languages"
|
||||
|
||||
import type { LangParams } from "@/types/params"
|
||||
|
||||
/**
|
||||
* A hook to get the current lang from the URL
|
||||
*/
|
||||
export default function useLang() {
|
||||
const { lang } = useParams<LangParams>()
|
||||
return lang
|
||||
|
||||
const parsedLang = languageSchema.safeParse(lang)
|
||||
return parsedLang.success ? parsedLang.data : Lang.en
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user