From 86aaa97809b90f72ffabadad79cdd103f653fae1 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 27 Oct 2025 16:30:03 +0200 Subject: [PATCH] fix(website): language-specific pages not properly determined --- apps/website/src/i18n.spec.ts | 1 + apps/website/src/i18n.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/website/src/i18n.spec.ts b/apps/website/src/i18n.spec.ts index eab06ba5a..fcc8d790a 100644 --- a/apps/website/src/i18n.spec.ts +++ b/apps/website/src/i18n.spec.ts @@ -19,6 +19,7 @@ describe("swapLocale", () => { expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started"); expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started"); expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/"); + expect(swapLocaleInUrl("/ro", "en")).toStrictEqual("/en"); }); }); diff --git a/apps/website/src/i18n.ts b/apps/website/src/i18n.ts index 435245217..10608e571 100644 --- a/apps/website/src/i18n.ts +++ b/apps/website/src/i18n.ts @@ -35,7 +35,13 @@ export function mapLocale(locale: string) { export function swapLocaleInUrl(url: string, newLocale: string) { const components = url.split("/"); if (components.length === 2) { - return `/${newLocale}${url}`; + const potentialLocale = components[1]; + const correspondingLocale = LOCALES.find(l => l.id === potentialLocale); + if (correspondingLocale) { + return `/${newLocale}`; + } else { + return `/${newLocale}${url}`; + } } else { components[1] = newLocale; return components.join("/");