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
+14 -12
View File
@@ -1,21 +1,23 @@
import { routing } from "../i18n/routing";
import { appLocales } from "../i18n/routing";
export type AppLocale = (typeof routing.locales)[number];
export type AppLocale = (typeof appLocales)[number];
export function resolveLocale(locale: string): AppLocale {
if (locale === "en" || locale === "ar") {
return locale;
}
export const FALLBACK_LOCALE: AppLocale = "de";
return routing.defaultLocale;
export function isSupportedLocale(locale: string | undefined | null): locale is AppLocale {
return locale === "de" || locale === "en" || locale === "ar";
}
export function resolveLocale(locale: string | undefined | null, fallbackLocale: AppLocale): AppLocale {
return isSupportedLocale(locale) ? locale : fallbackLocale;
}
export function getDirection(locale: string): "ltr" | "rtl" {
return resolveLocale(locale) === "ar" ? "rtl" : "ltr";
return locale === "ar" ? "rtl" : "ltr";
}
export function stripLocalePrefix(pathname: string): string {
for (const locale of routing.locales) {
for (const locale of appLocales) {
if (pathname === `/${locale}`) {
return "/";
}
@@ -31,7 +33,7 @@ export function stripLocalePrefix(pathname: string): string {
export function getLocalizedPath(
locale: string,
pathname = "/",
defaultLocale: AppLocale = routing.defaultLocale,
defaultLocale: AppLocale,
): string {
return getLocalizedPathWithDefault(locale, pathname, defaultLocale);
}
@@ -39,9 +41,9 @@ export function getLocalizedPath(
export function getLocalizedPathWithDefault(
locale: string,
pathname = "/",
defaultLocale: AppLocale = routing.defaultLocale,
defaultLocale: AppLocale,
): string {
const localeKey = resolveLocale(locale);
const localeKey = resolveLocale(locale, defaultLocale);
const normalizedPath = pathname === "" ? "/" : pathname;
const strippedPath = stripLocalePrefix(normalizedPath);