mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-03 16:00:36 +01:00
Compare commits
5
Commits
v1.29.11
...
115fa5acad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
115fa5acad | ||
|
|
c24a2989fa | ||
|
|
a6cfb522b3 | ||
|
|
12e645f6e2 | ||
|
|
9a3f64fcd6 |
No files matched your search
@@ -1,26 +1,3 @@
|
|||||||
<script>
|
<script>
|
||||||
import locales from "@blitzkit/i18n/locales.json";
|
|
||||||
import { getBestLocale } from "../core/i18n/getBestLocale";
|
|
||||||
|
|
||||||
const isAPI = window.location.pathname.startsWith("/api");
|
|
||||||
const isI18nPath = locales.supported.some(({ locale }) =>
|
|
||||||
window.location.pathname.startsWith(`/${locale}/`)
|
|
||||||
);
|
|
||||||
const bestLocale = getBestLocale();
|
|
||||||
const currentPath = locales.supported.find(({ locale }) =>
|
|
||||||
window.location.pathname.startsWith(`/${locale}/`)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isAPI && // not an api, duh!
|
|
||||||
localStorage.getItem("preferred-locale") !== null && // no preference, so probably google's crawler
|
|
||||||
bestLocale !== currentPath?.locale // we need to redirect
|
|
||||||
) {
|
|
||||||
window.location.pathname = isI18nPath
|
|
||||||
? window.location.pathname.replace(
|
|
||||||
`/${currentPath?.locale}`,
|
|
||||||
bestLocale === undefined ? "" : `/${bestLocale}`
|
|
||||||
)
|
|
||||||
: `/${bestLocale}${window.location.pathname}`;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
@@ -5,11 +5,11 @@ export function getBestLocale() {
|
|||||||
localStorage.getItem("preferred-locale") ??
|
localStorage.getItem("preferred-locale") ??
|
||||||
navigator.language.split("-")[0];
|
navigator.language.split("-")[0];
|
||||||
const isSupported = locales.supported.some(
|
const isSupported = locales.supported.some(
|
||||||
({ locale }) => locale === desiredLocale
|
({ locale }) => locale === desiredLocale,
|
||||||
);
|
);
|
||||||
const isDefault = desiredLocale === locales.default;
|
const isDefault = desiredLocale === locales.default;
|
||||||
|
|
||||||
if (!isSupported || isDefault) return undefined;
|
if (!isSupported || isDefault) return locales.default;
|
||||||
|
|
||||||
return desiredLocale;
|
return desiredLocale;
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,8 @@ export const getStaticPaths = (async () => {
|
|||||||
.map((tank) =>
|
.map((tank) =>
|
||||||
parentPaths.map((parent) => ({
|
parentPaths.map((parent) => ({
|
||||||
params: { ...parent.params, id: tank.id },
|
params: { ...parent.params, id: tank.id },
|
||||||
}))
|
props: parent.props,
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
.flat();
|
.flat();
|
||||||
}) satisfies GetStaticPaths;
|
}) satisfies GetStaticPaths;
|
||||||
|
|||||||
Reference in new issue
Block a user