Use explicit widget language code

This commit is contained in:
rajchales-monito
2026-07-30 08:24:13 +02:00
parent d49c672feb
commit fb33bd3dd6
2 changed files with 7 additions and 28 deletions
+2 -15
View File
@@ -2,7 +2,7 @@
const boot = window.MaalFlows || {};
const apiBase = (boot.apiBase || "").replace(/\/$/, "") || new URL(document.currentScript.src).origin;
const siteKey = boot.siteKey || "9b-plus";
const lang = detectPageLanguage(boot);
const lang = normalizeLanguage(boot.lang);
const storageKey = `maalflows:${siteKey}`;
const pendingStorageKey = `${storageKey}:pending`;
const session = loadSession();
@@ -13,10 +13,7 @@
fetch(`${apiBase}/api/widget/config?${new URLSearchParams({
siteKey,
lang,
pageLang: document.documentElement.lang || "",
currentUrl: location.href,
browserLang: navigator.language || ""
lang
})}`)
.then((res) => res.json())
.then((config) => mount(config))
@@ -506,16 +503,6 @@
};
}
function detectPageLanguage(boot) {
const fromBoot = normalizeLanguage(boot.lang);
if (fromBoot) return fromBoot;
const fromUrl = normalizeLanguage(location.pathname.split("/").filter(Boolean)[0]);
if (fromUrl) return fromUrl;
const fromHtml = normalizeLanguage(document.documentElement.lang);
if (fromHtml) return fromHtml;
return normalizeLanguage(navigator.language) || "cs";
}
function normalizeLanguage(value) {
const text = String(value || "").trim().toLowerCase().replace("_", "-");
const match = text.match(/^[a-z]{2,3}/);