Skip to content

Commit 86aaa97

Browse files
committed
fix(website): language-specific pages not properly determined
1 parent c4c8fe2 commit 86aaa97

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

apps/website/src/i18n.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("swapLocale", () => {
1919
expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started");
2020
expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started");
2121
expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/");
22+
expect(swapLocaleInUrl("/ro", "en")).toStrictEqual("/en");
2223
});
2324
});
2425

apps/website/src/i18n.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ export function mapLocale(locale: string) {
3535
export function swapLocaleInUrl(url: string, newLocale: string) {
3636
const components = url.split("/");
3737
if (components.length === 2) {
38-
return `/${newLocale}${url}`;
38+
const potentialLocale = components[1];
39+
const correspondingLocale = LOCALES.find(l => l.id === potentialLocale);
40+
if (correspondingLocale) {
41+
return `/${newLocale}`;
42+
} else {
43+
return `/${newLocale}${url}`;
44+
}
3945
} else {
4046
components[1] = newLocale;
4147
return components.join("/");

0 commit comments

Comments
 (0)