mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: auto prefixor
This commit is contained in:
1 parent
ffe58de179
commit
260d819c77
6 files changed
+65
-34
No files matched your search
@@ -1,13 +1,10 @@
|
||||
import { Link, type LinkProps } from '@radix-ui/themes';
|
||||
import { getBestLocale } from '../core/i18n/getBestLocale';
|
||||
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
||||
|
||||
type LinkI18nProps = LinkProps & LocaleAcceptorProps;
|
||||
|
||||
export function LinkI18n({ locale, href, ...props }: LinkI18nProps) {
|
||||
const bestLocale = getBestLocale();
|
||||
const resolvedLocale = locale ?? bestLocale;
|
||||
const prefix = resolvedLocale === undefined ? '' : `/${resolvedLocale}`;
|
||||
const prefix = locale === undefined ? '' : `/${locale}`;
|
||||
|
||||
return (
|
||||
<Link href={href?.startsWith('/') ? `${prefix}${href}` : href} {...props} />
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
DEFAULT_LOCALE,
|
||||
localizedStrings,
|
||||
SUPPORTED_LOCALE_FLAGS,
|
||||
SUPPORTED_LOCALES,
|
||||
} from '@blitzkit/core';
|
||||
import { GlobeIcon } from '@radix-ui/react-icons';
|
||||
import { Flex, Select, Text } from '@radix-ui/themes';
|
||||
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
||||
import { BlitzKitTheme } from './BlitzKitTheme';
|
||||
|
||||
export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
|
||||
return (
|
||||
<BlitzKitTheme>
|
||||
<Flex justify="center" mt="4" py="6" align="center" gap="3">
|
||||
<Text size="5" trim="end" color="gray">
|
||||
<GlobeIcon width="1em" height="1em" />
|
||||
</Text>
|
||||
|
||||
<Select.Root
|
||||
defaultValue={locale}
|
||||
onValueChange={(locale) => {
|
||||
localStorage.setItem('preferred-locale', locale);
|
||||
window.location.pathname = `/${locale === DEFAULT_LOCALE ? '' : locale}`;
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
|
||||
<Select.Content>
|
||||
{SUPPORTED_LOCALES.map((locale) => (
|
||||
<Select.Item key={locale} value={locale}>
|
||||
{SUPPORTED_LOCALE_FLAGS[locale]}{' '}
|
||||
{localizedStrings[locale].common.locales[locale]}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</Flex>
|
||||
</BlitzKitTheme>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user