Start updating paraglide to v2
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import type { AvailableLanguageTag } from "@/paraglide/runtime.js"
|
||||
import type { AbsolutePathname, Project } from "@/types/types.ts"
|
||||
|
||||
interface TranslatedPathnames {
|
||||
@ -22,8 +21,6 @@ const paths: Set<NavLink> = new Set([
|
||||
"/uses",
|
||||
])
|
||||
|
||||
const projectPaths: Set<string> = new Set<string>(["homepage", "sb1budget"])
|
||||
|
||||
/**
|
||||
* Defines the localized pathnames for the site.
|
||||
* The key must be used to navigate to the correct path.
|
||||
@ -38,49 +35,3 @@ for (const path of paths) {
|
||||
en: `/en${path}`,
|
||||
}
|
||||
}
|
||||
|
||||
export function localizePathname(
|
||||
pathname: NavLink,
|
||||
locale: AvailableLanguageTag,
|
||||
): 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("/")}`
|
||||
}
|
||||
return localizedPathname
|
||||
}
|
||||
return pathname
|
||||
}
|
||||
|
||||
export function resolvePathname(pathname: string): AbsolutePathname {
|
||||
if (pathname.startsWith("/en")) {
|
||||
return pathname.slice(3) as AbsolutePathname
|
||||
}
|
||||
return pathname as AbsolutePathname
|
||||
}
|
||||
|
||||
export function isAbsolutePathname(path: string): path is AbsolutePathname {
|
||||
return path.startsWith("/")
|
||||
}
|
||||
|
||||
export function isNavLink(path: string): path is NavLink {
|
||||
let basePath = path
|
||||
if (path.startsWith("/en")) {
|
||||
basePath = path.slice(2)
|
||||
}
|
||||
if (paths.has(basePath as NavLink)) {
|
||||
return true
|
||||
}
|
||||
const pathSplit = basePath.split("/").slice(1)
|
||||
return (
|
||||
pathSplit.length === 2 &&
|
||||
pathSplit[0] === "projects" &&
|
||||
projectPaths.has(pathSplit[1])
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user