feat: footer lang

This commit is contained in:
tresabhi committed 2025-01-15 13:10:57 -06:00
1 parent 4e80490fd4
commit baa16840df
5 files changed
+37 -19

No files matched your search

+8 -2
View File
@@ -1,12 +1,14 @@
---
import { assertSecret, fetchGameDefinitions } from '@blitzkit/core';
import { Code, Flex, Heading, Link, Text } from '@radix-ui/themes';
import { DEFAULT_LOCALE } from '@blitzkit/i18n';
import { Box, Code, Flex, Heading, Link, Text } from '@radix-ui/themes';
import packageJson from '../../../../package.json';
import { getStrings } from '../core/i18n/getStrings';
import { LocaleSwitcherThemeWrapper } from './LocaleSwitcher';
const gameDefinitions = await fetchGameDefinitions();
const PUBLIC_ASSET_BRANCH = assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH);
const { locale } = Astro.params;
const locale = Astro.params.locale ?? DEFAULT_LOCALE;
const strings = getStrings(locale);
---
@@ -39,6 +41,10 @@ const strings = getStrings(locale);
<Text size="1" color="gray">
{strings.website.footer.copyright}
</Text>
<Box mt="2">
<LocaleSwitcherThemeWrapper {locale} client:load />
</Box>
</Flex>
<Flex
@@ -7,6 +7,15 @@ import {
} from '@blitzkit/i18n';
import { Select } from '@radix-ui/themes';
import type { LocaleAcceptorProps } from '../hooks/useLocale';
import { BlitzKitTheme } from './BlitzKitTheme';
export function LocaleSwitcherThemeWrapper({ locale }: LocaleAcceptorProps) {
return (
<BlitzKitTheme style={{ background: 'transparent' }}>
<LocaleSwitcher locale={locale} />
</BlitzKitTheme>
);
}
export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
return (
@@ -14,7 +23,19 @@ export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
defaultValue={locale}
onValueChange={(locale) => {
localStorage.setItem('preferred-locale', locale);
window.location.pathname = `/${locale === DEFAULT_LOCALE ? '' : locale}`;
let rawPath = window.location.pathname;
for (const supportedLocale of SUPPORTED_LOCALES) {
if (window.location.pathname.startsWith(`/${supportedLocale}`)) {
rawPath = rawPath.replace(`/${supportedLocale}`, '');
break;
}
}
window.location.pathname = `${
locale === DEFAULT_LOCALE ? '' : `/${locale}`
}${rawPath}`;
}}
>
<Select.Trigger />