import React, { useEffect } from 'react'; import { Head, Link, usePage, router } from '@inertiajs/react'; import { useLocalizedRoutes } from '@/hooks/useLocalizedRoutes'; import { useTranslation } from 'react-i18next'; interface MarketingLayoutProps { children: React.ReactNode; title?: string; } const MarketingLayout: React.FC = ({ children, title }) => { const page = usePage<{ translations?: Record> }>(); const { url } = page; const { t } = useTranslation('marketing'); const i18n = useTranslation(); const { locale, localizedPath } = useLocalizedRoutes(); useEffect(() => { const localeCandidate = locale || (url.startsWith('/en/') ? 'en' : 'de'); if (localeCandidate && i18n.i18n.language !== localeCandidate) { i18n.i18n.changeLanguage(localeCandidate); } }, [url, i18n, locale]); const marketing = page.props.translations?.marketing ?? {}; const getString = (key: string, fallback: string) => { const value = marketing[key]; return typeof value === 'string' ? value : fallback; }; const activeLocale = locale || (url.startsWith('/en/') ? 'en' : 'de'); const alternateLocale = activeLocale === 'de' ? 'en' : 'de'; const path = url.replace(/^\/(de|en)/, ''); const canonicalUrl = `https://fotospiel.app${localizedPath(path || '/')}`; const handleLocaleChange = (nextLocale: string) => { const normalizedPath = url.replace(/^\/(de|en)/, '') || '/'; const destination = normalizedPath === '/' ? `/${nextLocale}` : `/${nextLocale}${normalizedPath}`; router.visit(destination); }; return ( <> {title || t('meta.title', getString('title', 'Fotospiel'))}
{children}
); }; export default MarketingLayout;