mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: locale redirect
This commit is contained in:
1 parent
1843eb3bcf
commit
844965bcb0
2 files changed
+16
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
export const SUPPORTED_LOCALES = ['en', 'es', 'hr', 'ru', 'uk', 'cn'];
|
export const SUPPORTED_LOCALES = ['en', 'es', 'hr', 'ru', 'uk', 'cn'];
|
||||||
|
export const DEFAULT_LOCALE = SUPPORTED_LOCALES[0];
|
||||||
export const LOCALE_FILES: Record<(typeof SUPPORTED_LOCALES)[number], string> =
|
export const LOCALE_FILES: Record<(typeof SUPPORTED_LOCALES)[number], string> =
|
||||||
{
|
{
|
||||||
en: 'en-US',
|
en: 'en-US',
|
||||||
|
|||||||
@@ -36,6 +36,21 @@ const isRoot = pathname === '/';
|
|||||||
<link rel="sitemap" href="/sitemap-index.xml" />
|
<link rel="sitemap" href="/sitemap-index.xml" />
|
||||||
|
|
||||||
<Party3 />
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in new issue
Block a user