22 lines
704 B
TypeScript
22 lines
704 B
TypeScript
import { usePage } from '@inertiajs/react';
|
|
import { buildLocalizedPath, defaultLocaleRewrites } from '@/lib/localizedPath';
|
|
import { useLocale } from './useLocale';
|
|
|
|
export const useLocalizedRoutes = () => {
|
|
const { props } = usePage<{ supportedLocales?: string[]; defaultLocale?: string }>();
|
|
const locale = useLocale();
|
|
const supportedLocales = props.supportedLocales ?? [];
|
|
const defaultLocale = props.defaultLocale ?? 'de';
|
|
|
|
const localizedPath = (path: string | null | undefined, targetLocale?: string) =>
|
|
buildLocalizedPath(
|
|
path,
|
|
targetLocale ?? locale,
|
|
supportedLocales,
|
|
defaultLocale,
|
|
defaultLocaleRewrites,
|
|
);
|
|
|
|
return { localizedPath };
|
|
};
|