Fix localization on detailed project pages.
All checks were successful
Build and deploy website / build (push) Successful in 34s

Fix way too much padding on <br/> tags.

Added some old project entries.

Added Project as a convenience type.

Added link class to all a tags to easier distinguish links in text.

Signed-off-by: Martin Berg Alstad <git@martials.no>
This commit is contained in:
2024-10-20 22:25:52 +02:00
parent 941a93f8a5
commit b9f7b63aa9
11 changed files with 86 additions and 27 deletions

View File

@ -1,12 +1,18 @@
import type { AvailableLanguageTag } from "@/paraglide/runtime.js"
import type { AbsolutePathname } from "@/types/types.ts"
import type { AbsolutePathname, Project } from "@/types/types.ts"
interface TranslatedPathnames {
nb: AbsolutePathname
en: `/en${AbsolutePathname}`
}
export type NavLink = "/" | "/contact" | "/projects" | "/links" | "/hardware"
export type NavLink =
"/"
| "/contact"
| "/projects"
| `/projects/${Project["id"]}`
| "/links"
| "/hardware"
const paths: Set<NavLink> = new Set([
"/",
@ -34,9 +40,19 @@ for (const path of paths) {
export function localizePathname(
pathname: NavLink,
locale: AvailableLanguageTag
) {
if (pathnames[pathname]) {
return pathnames[pathname][locale]
): string {
const pathnameParts = pathname.split("/")
const firstSegment: AbsolutePathname = `/${pathnameParts[1]}`
if (pathnames[firstSegment]) {
const localizedPathname = pathnames[firstSegment][locale]
const rest = pathnameParts.slice(2)
if (rest.length > 0) {
return `${localizedPathname}/${rest.join("/")}`
} else {
return localizedPathname
}
}
return pathname
}