feat: some locale links

This commit is contained in:
tresabhi committed 2024-12-27 13:43:25 -06:00
1 parent eb5527706e
commit 8203db3dc2
4 files changed
+47 -12

No files matched your search

+12 -6
View File
@@ -2,8 +2,10 @@
import { assertSecret, fetchGameDefinitions } from '@blitzkit/core'; import { assertSecret, fetchGameDefinitions } from '@blitzkit/core';
import { Code, Flex, Heading, Link, Text } from '@radix-ui/themes'; import { Code, Flex, Heading, Link, Text } from '@radix-ui/themes';
import packageJson from '../../../../package.json'; import packageJson from '../../../../package.json';
import { LinkI18n } from './LinkI18n';
const gameDefinitions = await fetchGameDefinitions(); const gameDefinitions = await fetchGameDefinitions();
const { locale } = Astro.params;
--- ---
<style> <style>
@@ -13,6 +15,7 @@ const gameDefinitions = await fetchGameDefinitions();
</style> </style>
<Flex className="footer" gap="6" p="6" direction="column" align="center"> <Flex className="footer" gap="6" p="6" direction="column" align="center">
{locale}
<Flex <Flex
align="center" align="center"
justify="between" justify="between"
@@ -68,7 +71,9 @@ const gameDefinitions = await fetchGameDefinitions();
sm: 'start', sm: 'start',
}} }}
> >
<Link href="/docs/about/credits" color="gray"> Credits </Link> <LinkI18n {locale} href="/docs/about/credits" color="gray"
>Credits</LinkI18n
>
<Link <Link
href="https://discord.gg/nDt7AjGJQH" href="https://discord.gg/nDt7AjGJQH"
target="_blank" target="_blank"
@@ -83,7 +88,8 @@ const gameDefinitions = await fetchGameDefinitions();
> >
GitHub GitHub
</Link> </Link>
<Link href="/docs/patches" color="gray"> Patches </Link> <LinkI18n {locale} href="/docs/patches" color="gray">Patches</LinkI18n
>
</Flex> </Flex>
</Flex> </Flex>
@@ -101,12 +107,12 @@ const gameDefinitions = await fetchGameDefinitions();
> >
<Heading size="3">Legal</Heading> <Heading size="3">Legal</Heading>
<Flex direction="column"> <Flex direction="column">
<Link href="/docs/legal/privacy-policy" color="gray"> <LinkI18n {locale} href="/docs/legal/privacy-policy" color="gray">
Privacy policy Privacy policy
</Link> </LinkI18n>
<Link href="/docs/legal/terms-of-service" color="gray"> <LinkI18n {locale} href="/docs/legal/terms-of-service" color="gray">
Terms of service Terms of service
</Link> </LinkI18n>
</Flex> </Flex>
</Flex> </Flex>
</Flex> </Flex>
@@ -0,0 +1,19 @@
import { Link, type LinkProps } from '@radix-ui/themes';
import { getBestLocale } from '../core/i18n/getBestLocale';
type LinkI18nProps = LinkProps & {
locale: string | undefined;
};
export function LinkI18n({ locale, href, ...props }: LinkI18nProps) {
const bestLocale = getBestLocale();
const resolvedLocale = locale ?? bestLocale;
const prefix = resolvedLocale === undefined ? '' : `/${resolvedLocale}`;
return (
<Link
href={href === undefined ? undefined : `${prefix}${href}`}
{...props}
/>
);
}
@@ -0,0 +1,11 @@
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@blitzkit/core';
export function getBestLocale() {
const desiredLocale = navigator.language.split('-')[0];
const isSupported = SUPPORTED_LOCALES.includes(desiredLocale);
const isDefault = desiredLocale === DEFAULT_LOCALE;
if (!isSupported || isDefault) return undefined;
return desiredLocale;
}
@@ -38,17 +38,16 @@ const isRoot = pathname === '/';
<Party3 /> <Party3 />
<script> <script>
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@blitzkit/core'; import { SUPPORTED_LOCALES } from '@blitzkit/core';
import { getBestLocale } from '../core/i18n/getBestLocale';
const isI18nPath = SUPPORTED_LOCALES.some((locale) => const isI18nPath = SUPPORTED_LOCALES.some((locale) =>
window.location.pathname.startsWith(`/${locale}`), window.location.pathname.startsWith(`/${locale}`),
); );
const desiredLocale = navigator.language.split('-')[0]; const bestLocale = getBestLocale();
const isSupported = SUPPORTED_LOCALES.includes(desiredLocale);
const isDefault = desiredLocale === DEFAULT_LOCALE;
if (!isI18nPath && isSupported && !isDefault) { if (!isI18nPath && bestLocale !== undefined) {
window.location.pathname = `/${desiredLocale}${window.location.pathname}`; window.location.pathname = `/${bestLocale}${window.location.pathname}`;
} }
</script> </script>
</head> </head>