feat: implement multi-language support, SEO metadata, schema markup, and legal pages
This commit is contained in:
@@ -1,27 +1,46 @@
|
||||
'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)
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, useEffect, 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,
|
||||
})
|
||||
|
||||
function getInitialLang(): Lang {
|
||||
if (typeof document === 'undefined') return 'de'
|
||||
const match = document.cookie.match(/(?:^|;\s*)lang=([^;]+)/)
|
||||
const val = match?.[1]
|
||||
return val === 'en' || val === 'es' || val === 'de' ? val : 'de'
|
||||
}
|
||||
|
||||
export function LangProvider({ children }: { children: ReactNode }) {
|
||||
const [lang, setLangState] = useState<Lang>('de')
|
||||
|
||||
useEffect(() => {
|
||||
setLangState(getInitialLang())
|
||||
}, [])
|
||||
|
||||
const setLang = (l: Lang) => {
|
||||
document.cookie = `lang=${l};path=/;max-age=31536000;SameSite=Lax`
|
||||
// Update <html lang> for the current page visit without a full reload
|
||||
document.documentElement.lang = l
|
||||
setLangState(l)
|
||||
}
|
||||
|
||||
return (
|
||||
<LangContext.Provider value={{ lang, setLang, t: translations[lang] }}>
|
||||
{children}
|
||||
</LangContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useLang = () => useContext(LangContext)
|
||||
|
||||
Reference in New Issue
Block a user