Files
igaming-template/layouts/partials/locale-switcher.html
T
2026-07-21 20:54:20 +03:00

92 lines
3.8 KiB
HTML

{{- /* locale-switcher.html — HEADLESS region/compliance data layer.
This partial no longer renders a visible region selector (the header now
exposes only the content language switcher). It still applies the stored
or default locale on load so all locale-dependent COMPLIANCE bindings
render correctly across the site:
[data-age-value] age restriction
[data-rg-name] responsible-gambling org name
[data-rg-link] responsible-gambling URL
[data-locale-currency]currency symbol (payment table)
[data-payment-row] show only methods available in the locale
[data-kyc-row] highlight the matching KYC row
Data comes from data/locales.yaml (exposed as window.__LOCALES__).
window.applyLocale(loc) and the "localechange" event remain the public
API, so a region selector can be reintroduced later without touching the
compliance logic. */ -}}
<script>
(function () {
function apply(loc) {
var locales = window.__LOCALES__ || [];
var entry = null;
for (var i = 0; i < locales.length; i++) {
if (locales[i].locale === loc) { entry = locales[i]; break; }
}
if (!entry) {
if (!locales.length) return;
entry = locales[0];
loc = entry.locale;
}
try { localStorage.setItem("siteLocale", loc); } catch (e) {}
document.querySelectorAll("[data-age-value]").forEach(function (el) {
el.textContent = entry.ageRestriction;
});
document.querySelectorAll("[data-rg-name]").forEach(function (el) {
el.textContent = entry.responsibleGamblingOrgName;
});
document.querySelectorAll("[data-rg-link]").forEach(function (el) {
el.setAttribute("href", entry.responsibleGamblingUrl);
});
document.querySelectorAll("[data-locale-currency]").forEach(function (el) {
el.textContent = entry.currencySymbol;
});
// Show only payment methods available in the selected locale.
document.querySelectorAll("[data-payment-row]").forEach(function (row) {
var locs = (row.getAttribute("data-locales") || "").split(",");
row.hidden = locs.indexOf(loc) === -1;
});
// Highlight the KYC row matching the selected locale.
document.querySelectorAll("[data-kyc-row]").forEach(function (row) {
row.classList.toggle("is-active-locale", row.getAttribute("data-locale") === loc);
});
// Kept for backwards compatibility if a region selector is reintroduced.
document.querySelectorAll("[data-locale-switcher]").forEach(function (sel) {
sel.value = loc;
});
document.dispatchEvent(new CustomEvent("localechange", { detail: { locale: loc, entry: entry } }));
}
window.applyLocale = apply;
function init() {
var brand = window.__BRAND__ || {};
var pageLocale = document.documentElement.lang || "";
var stored = null;
try { stored = localStorage.getItem("siteLocale"); } catch (e) {}
var preferred = stored;
if (pageLocale) {
var locales = window.__LOCALES__ || [];
for (var i = 0; i < locales.length; i++) {
if (locales[i].locale === pageLocale || locales[i].locale.indexOf(pageLocale + "-") === 0) {
preferred = locales[i].locale;
break;
}
}
}
apply(preferred || brand.defaultLocale);
// If a region selector is present (reintroduced later), wire it up.
document.querySelectorAll("[data-locale-switcher]").forEach(function (sel) {
sel.addEventListener("change", function () { apply(this.value); });
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();
</script>