feat: locale redirect

This commit is contained in:
tresabhi committed 2024-12-27 12:55:52 -06:00
1 parent 1843eb3bcf
commit 844965bcb0
2 files changed
+16

No files matched your search

@@ -36,6 +36,21 @@ const isRoot = pathname === '/';
<link rel="sitemap" href="/sitemap-index.xml" />
<Party3 />
<script>
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@blitzkit/core';
const isI18nPath = SUPPORTED_LOCALES.some((locale) =>
window.location.pathname.startsWith(`/${locale}`),
);
const desiredLocale = navigator.language.split('-')[0];
const isSupported = SUPPORTED_LOCALES.includes(desiredLocale);
const isDefault = desiredLocale === DEFAULT_LOCALE;
if (!isI18nPath && isSupported && !isDefault) {
window.location.pathname = `/${desiredLocale}${window.location.pathname}`;
}
</script>
</head>
<body>