fixed language switching in the frontend
This commit is contained in:
@@ -26,8 +26,7 @@ type PageProps = {
|
||||
const MarketingLayout: React.FC<MarketingLayoutProps> = ({ children, title }) => {
|
||||
const page = usePage<PageProps>();
|
||||
const { url } = page;
|
||||
const { t } = useTranslation('marketing');
|
||||
const i18n = useTranslation();
|
||||
const { t, i18n, ready } = useTranslation(['marketing', 'common', 'legal', 'auth']);
|
||||
const { locale, analytics, supportedLocales = ['de', 'en'], appUrl, auth } = page.props;
|
||||
const user = auth?.user ?? null;
|
||||
const { localizedPath } = useLocalizedRoutes();
|
||||
@@ -94,11 +93,20 @@ const MarketingLayout: React.FC<MarketingLayoutProps> = ({ children, title }) =>
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (locale && i18n.i18n.language !== locale) {
|
||||
i18n.i18n.changeLanguage(locale);
|
||||
if (locale && i18n.language !== locale) {
|
||||
i18n.changeLanguage(locale);
|
||||
}
|
||||
}, [locale, i18n]);
|
||||
|
||||
if (!ready) {
|
||||
return (
|
||||
<div className="min-h-screen bg-white text-gray-900 dark:bg-gray-950 dark:text-gray-50 flex items-center justify-center">
|
||||
<Head title="Fotospiel" />
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">Lade Inhalte …</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const marketing = page.props.translations?.marketing ?? {};
|
||||
|
||||
const getString = (key: string, fallback: string) => {
|
||||
@@ -132,11 +140,13 @@ const MarketingLayout: React.FC<MarketingLayoutProps> = ({ children, title }) =>
|
||||
const targetPath = localizedPath(relativePath, nextLocale);
|
||||
const targetUrl = `${targetPath}${rawQuery ? `?${rawQuery}` : ''}`;
|
||||
|
||||
i18n.i18n.changeLanguage(nextLocale);
|
||||
setMobileMenuOpen(false);
|
||||
router.visit(targetUrl, {
|
||||
replace: true,
|
||||
preserveState: false,
|
||||
onSuccess: () => {
|
||||
i18n.changeLanguage(nextLocale);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user