Use explicit widget language code
This commit is contained in:
+2
-15
@@ -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}/);
|
||||
|
||||
Reference in New Issue
Block a user