1/* Language switching. Staff edit js/translations.js â not this file. */ 2 3function currentLang() { 4 return localStorage.getItem("home-lang") || "en"; 5} 6 7function setLang(lang) { 8 localStorage.setItem("home-lang", lang); 9 applyLanguage(); 10} 11 12function toggleLang() { 13 setLang(currentLang() === "en" ? "es" : "en"); 14} 15 16/* Look up a translated string by key, falling back to English. */ 17function t(key) { 18 const entry = TRANSLATIONS[key]; 19 if (!entry) return key; 20 return entry[currentLang()] || entry.en; 21} 22 23/* Apply the current language to every element tagged with data-i18n, 24 update the toggle button, and redraw any notice lists. */ 25function applyLanguage() { 26 const lang = currentLang(); 27 document.documentElement.lang = lang; 28 29 document.querySelectorAll("[data-i18n]").forEach((el) => { 30 const entry = TRANSLATIONS[el.dataset.i18n]; 31 if (entry) el.innerHTML = entry[lang] || entry.en; 32 }); 33 34 const btn = document.getElementById("lang-toggle"); 35 if (btn) { 36 // The button always shows the language you would switch TO. 37 btn.textContent = lang === "en" ? "Español" : "English"; 38 btn.setAttribute("lang", lang === "en" ? "es" : "en"); 39 btn.setAttribute("aria-label", lang === "en" ? "Cambiar el sitio a español" : "Switch site to English"); 40 } 41 42 if (typeof NOTICE_REDRAWS !== "undefined") NOTICE_REDRAWS.forEach((fn) => fn()); 43} 44 45document.addEventListener("DOMContentLoaded", () => { 46 const btn = document.getElementById("lang-toggle"); 47 if (btn) btn.addEventListener("click", (e) => { e.preventDefault(); toggleLang(); }); 48 applyLanguage(); 49});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.