Fix runtime default locale resolution
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-15 06:02:27 +01:00
parent 9b8409a7d3
commit c18128c965
29 changed files with 330 additions and 108 deletions
+10 -9
View File
@@ -2,7 +2,7 @@ import createMiddleware from "next-intl/middleware";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { appLocales, createI18nRouting, routing } from "./i18n/routing";
import { appLocales, createI18nRouting } from "./i18n/routing";
import {
fromDevelopmentAdminPath,
getAdminBaseUrl,
@@ -14,7 +14,12 @@ import {
isLegacyAdminPath,
toInternalAdminPath,
} from "./lib/admin-routing";
import { getLocalizedPathWithDefault, stripLocalePrefix } from "./lib/locale";
import {
FALLBACK_LOCALE,
getLocalizedPathWithDefault,
isSupportedLocale,
stripLocalePrefix,
} from "./lib/locale";
const ADMIN_SESSION_COOKIE = "moh_admin_session";
@@ -23,10 +28,6 @@ type SiteRuntimeState = {
maintenanceEnabled: boolean;
};
function isSupportedLocale(locale: string | undefined): locale is (typeof appLocales)[number] {
return locale === "ar" || locale === "en" || locale === "de";
}
function getPathLocale(pathname: string, fallbackLocale: (typeof appLocales)[number]) {
const locale = pathname.split("/")[1];
@@ -48,7 +49,7 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
if (!response.ok) {
return {
defaultLocale: routing.defaultLocale,
defaultLocale: FALLBACK_LOCALE,
maintenanceEnabled: false,
};
}
@@ -59,12 +60,12 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
};
return {
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : routing.defaultLocale,
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : FALLBACK_LOCALE,
maintenanceEnabled: data.maintenanceEnabled === true,
};
} catch {
return {
defaultLocale: routing.defaultLocale,
defaultLocale: FALLBACK_LOCALE,
maintenanceEnabled: false,
};
}