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
+15 -1
View File
@@ -1,8 +1,22 @@
import { describe, expect, it } from "vitest";
import { getLocalizedPathWithDefault } from "../lib/locale";
import { FALLBACK_LOCALE, getLocalizedPathWithDefault, isSupportedLocale, resolveLocale } from "../lib/locale";
describe("locale path helpers", () => {
it("recognizes supported locales explicitly", () => {
expect(isSupportedLocale("ar")).toBe(true);
expect(isSupportedLocale("en")).toBe(true);
expect(isSupportedLocale("de")).toBe(true);
expect(isSupportedLocale("fr")).toBe(false);
expect(isSupportedLocale(undefined)).toBe(false);
});
it("resolves invalid locales with an explicit fallback", () => {
expect(resolveLocale("ar", "de")).toBe("ar");
expect(resolveLocale("fr", "en")).toBe("en");
expect(resolveLocale("", FALLBACK_LOCALE)).toBe("de");
});
it("keeps the configured default locale on the bare domain", () => {
expect(getLocalizedPathWithDefault("ar", "/", "ar")).toBe("/");
expect(getLocalizedPathWithDefault("de", "/", "ar")).toBe("/de");