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:
24
src/utils/linking.ts
Normal file
24
src/utils/linking.ts
Normal 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
|
||||
}
|
Reference in New Issue
Block a user