Skip to content

Commit

Permalink
fix: i18n routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed Oct 15, 2024
1 parent aae897c commit f991da1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/i18n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ export function useTranslations(lang: Language) {
};
}

const removeLocalePrefix = (path: string): string => {
const localePattern = new RegExp(
`^/(${Object.keys(languages).join("|")})\\b`,
);
return path.replace(localePattern, "");
};

export type LocalePath = { lang: Language; path: string };
export const getLocalePaths = (url: URL): LocalePath[] => {
const cleanPath = removeLocalePrefix(url.pathname);
return Object.keys(languages).map((lang) => ({
lang: lang as Language,
path: getRelativeLocaleUrl(lang, url.pathname.replace(/^\/[a-zA-Z-]+/, "")),
path: getRelativeLocaleUrl(lang, cleanPath),
}));
};

Expand Down

0 comments on commit f991da1

Please sign in to comment.