Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/vinext/src/server/pages-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ export function extractLocaleFromUrl(
const parts = pathname.split("/").filter(Boolean);
const query = url.includes("?") ? url.slice(url.indexOf("?")) : "";

if (parts.length > 0 && i18nConfig.locales.includes(parts[0])) {
const locale = parts[0];
const locale = i18nConfig.locales.find(
(candidate) => candidate.toLowerCase() === parts[0]?.toLowerCase(),
);
if (locale) {
const rest = "/" + parts.slice(1).join("/");
return { locale, url: (rest || "/") + query, hadPrefix: true };
}
Expand Down
8 changes: 8 additions & 0 deletions tests/pages-i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ describe("Pages i18n domain helpers", () => {
expect(addLocalePrefix("/FR/about", "fr", "en")).toBe("/FR/about");
});

it("routes locale prefixes case-insensitively using the configured locale", () => {
expect(resolvePagesI18nRequest("/FR/about", i18n)).toMatchObject({
hadPrefix: true,
locale: "fr",
url: "/about",
});
});

it("does not let NEXT_LOCALE override the current domain default locale", () => {
expect(
getLocaleRedirect({
Expand Down
Loading