2024-12-27 13:43:25 -06:00
|
|
|
import { Link, type LinkProps } from '@radix-ui/themes';
|
|
|
|
|
import { getBestLocale } from '../core/i18n/getBestLocale';
|
2025-01-06 20:31:21 -06:00
|
|
|
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
2024-12-27 13:43:25 -06:00
|
|
|
|
2025-01-06 20:31:21 -06:00
|
|
|
type LinkI18nProps = LinkProps & LocaleAcceptorProps;
|
2024-12-27 13:43:25 -06:00
|
|
|
|
|
|
|
|
export function LinkI18n({ locale, href, ...props }: LinkI18nProps) {
|
|
|
|
|
const bestLocale = getBestLocale();
|
|
|
|
|
const resolvedLocale = locale ?? bestLocale;
|
|
|
|
|
const prefix = resolvedLocale === undefined ? '' : `/${resolvedLocale}`;
|
|
|
|
|
|
|
|
|
|
return (
|
2024-12-27 14:01:59 -06:00
|
|
|
<Link href={href?.startsWith('/') ? `${prefix}${href}` : href} {...props} />
|
2024-12-27 13:43:25 -06:00
|
|
|
);
|
|
|
|
|
}
|