Button group to switch languages.

Localized pathname function for links.

inlang/paraglide-astro package

Signed-off-by: Martin Berg Alstad <git@martials.no>
This commit is contained in:
2024-10-09 21:30:05 +02:00
parent 87184c431d
commit c701a510f7
8 changed files with 800 additions and 8 deletions

24
src/utils/linking.ts Normal file
View File

@ -0,0 +1,24 @@
import type { AvailableLanguageTag } from "@/paraglide/runtime.js"
type AbsolutePathname = `/${string}`
// TODO what?
// https://inlang.com/m/iljlwzfs/paraglide-astro-i18n
const pathnames: Record<AbsolutePathname,
Record<AvailableLanguageTag, AbsolutePathname>
> = {
"/contact-me": {
nb: "/contact-me",
en: "/en/contact-me"
}
}
export function localizePathname(
pathname: AbsolutePathname,
locale: AvailableLanguageTag
) {
if (pathnames[pathname]) {
return pathnames[pathname][locale]
}
return pathname
}