Initial commit for Greenlens
This commit is contained in:
27
greenlns-landing/context/LangContext.tsx
Normal file
27
greenlns-landing/context/LangContext.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, ReactNode } from 'react'
|
||||
import { Lang, translations } from '@/lib/i18n'
|
||||
|
||||
interface LangCtx {
|
||||
lang: Lang
|
||||
setLang: (l: Lang) => void
|
||||
t: typeof translations.de
|
||||
}
|
||||
|
||||
const LangContext = createContext<LangCtx>({
|
||||
lang: 'de',
|
||||
setLang: () => {},
|
||||
t: translations.de,
|
||||
})
|
||||
|
||||
export function LangProvider({ children }: { children: ReactNode }) {
|
||||
const [lang, setLang] = useState<Lang>('de')
|
||||
return (
|
||||
<LangContext.Provider value={{ lang, setLang, t: translations[lang] }}>
|
||||
{children}
|
||||
</LangContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useLang = () => useContext(LangContext)
|
||||
Reference in New Issue
Block a user