SEO
This commit is contained in:
@@ -17,6 +17,9 @@ const LangContext = createContext<LangCtx>({
|
||||
|
||||
function getInitialLang(): Lang {
|
||||
if (typeof document === 'undefined') return 'de'
|
||||
if (window.location.pathname === '/') return 'de'
|
||||
if (window.location.pathname === '/de' || window.location.pathname.startsWith('/de/')) return 'de'
|
||||
if (window.location.pathname === '/es' || window.location.pathname.startsWith('/es/')) return 'es'
|
||||
const match = document.cookie.match(/(?:^|;\s*)lang=([^;]+)/)
|
||||
const val = match?.[1]
|
||||
return val === 'en' || val === 'es' || val === 'de' ? val : 'de'
|
||||
@@ -26,7 +29,9 @@ export function LangProvider({ children }: { children: ReactNode }) {
|
||||
const [lang, setLangState] = useState<Lang>('de')
|
||||
|
||||
useEffect(() => {
|
||||
setLangState(getInitialLang())
|
||||
const initialLang = getInitialLang()
|
||||
document.documentElement.lang = initialLang
|
||||
setLangState(initialLang)
|
||||
}, [])
|
||||
|
||||
const setLang = (l: Lang) => {
|
||||
|
||||
Reference in New Issue
Block a user