neuer checkout-pfad: /de/bestellen/paketID und /en/checkout/PackageID

This commit is contained in:
Codex Agent
2025-12-20 16:17:21 +01:00
parent 18297aa3f1
commit 6500b8df2c
18 changed files with 331 additions and 345 deletions

View File

@@ -6,6 +6,8 @@ export const defaultLocaleRewrites: LocaleRewriteMap = {
'/contact': { de: '/kontakt' },
'/so-funktionierts': { en: '/how-it-works' },
'/how-it-works': { de: '/so-funktionierts' },
'/bestellen': { en: '/checkout' },
'/checkout': { de: '/bestellen' },
'/anlaesse': { en: '/occasions' },
'/anlaesse/hochzeit': { en: '/occasions/wedding' },
'/anlaesse/geburtstag': { en: '/occasions/birthday' },
@@ -28,6 +30,34 @@ const sanitizePath = (input: string): string => {
return withoutTrailing;
};
const resolveRewrite = (
path: string,
targetLocale: string,
rewrites: LocaleRewriteMap,
): string => {
const exact = rewrites[path];
if (exact) {
return exact[targetLocale] ?? path;
}
const prefixKey = Object.keys(rewrites)
.filter((key) => key !== '/' && path.startsWith(`${key}/`))
.sort((a, b) => b.length - a.length)[0];
if (!prefixKey) {
return path;
}
const replacement = rewrites[prefixKey]?.[targetLocale];
if (!replacement) {
return path;
}
const suffix = path.slice(prefixKey.length);
return `${replacement}${suffix}`;
};
export const buildLocalizedPath = (
path: string | null | undefined,
targetLocale: string | undefined,
@@ -47,8 +77,7 @@ export const buildLocalizedPath = (
const trimmed = path.trim();
const [rawPath, rawQuery] = trimmed.split('?');
const normalizedPath = sanitizePath(rawPath);
const rewritesForPath = rewrites[normalizedPath] ?? {};
const rewrittenPath = rewritesForPath[nextLocale] ?? normalizedPath;
const rewrittenPath = resolveRewrite(normalizedPath, nextLocale, rewrites);
const base = rewrittenPath === '/' ? `/${nextLocale}` : `/${nextLocale}${rewrittenPath}`;
const sanitisedBase = base.replace(/\/{2,}/g, '/');
const query = rawQuery ? `?${rawQuery}` : '';