Files
MatchLiveTv/backend/app/views/shared/_language_switcher.html.erb
eminuxandCursor 1d1cbf9f3f Localizza errori API, sistema layout mobile e documenta allineamento iOS.
Gli header Accept-Language dalle app e i fix di padding/menu sul web chiudono il giro password-policy; il doc guida il lavoro su Mac.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 14:14:42 +02:00

82 lines
2.5 KiB
ERB

<%# Selettore lingua a bandiere (allineato a destra nel menu) %>
<%# locals: (locale_path: nil) %>
<% current = current_language_option %>
<% target_path = locale_path || public_locale_path %>
<div class="lang-switcher" data-lang-switcher>
<button
type="button"
class="lang-switcher__toggle"
id="lang-switcher-toggle"
aria-haspopup="listbox"
aria-expanded="false"
aria-controls="lang-switcher-menu"
aria-label="<%= t('language.choose') %>: <%= current[:native] %>"
title="<%= current[:native] %>"
>
<span class="lang-switcher__flag" aria-hidden="true"><%= current[:flag] %></span>
<span class="lang-switcher__chevron" aria-hidden="true"></span>
</button>
<div
class="lang-switcher__menu"
id="lang-switcher-menu"
role="listbox"
aria-label="<%= t('language.label') %>"
hidden
>
<% language_options.each do |opt| %>
<% selected = opt[:code].to_s == current_locale.to_s %>
<%= button_to target_path,
method: :patch,
params: { locale: opt[:code] },
class: "lang-switcher__option#{' is-active' if selected}",
form: { class: "lang-switcher__option-form" },
role: "option",
aria: { selected: selected, label: opt[:native] },
title: opt[:native] do %>
<span class="lang-switcher__flag" aria-hidden="true"><%= opt[:flag] %></span>
<span class="visually-hidden"><%= opt[:native] %></span>
<% end %>
<% end %>
</div>
</div>
<script>
(function () {
var root = document.querySelector("[data-lang-switcher]");
if (!root || root.dataset.bound === "1") return;
root.dataset.bound = "1";
var toggle = root.querySelector(".lang-switcher__toggle");
var menu = root.querySelector(".lang-switcher__menu");
if (!toggle || !menu) return;
function setOpen(open) {
menu.hidden = !open;
toggle.setAttribute("aria-expanded", open ? "true" : "false");
root.classList.toggle("is-open", open);
}
toggle.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
setOpen(menu.hidden);
});
// Keep parent mobile nav open while interacting with the switcher UI.
root.addEventListener("click", function (e) {
if (e.target.closest(".lang-switcher__toggle")) {
e.stopPropagation();
}
});
document.addEventListener("click", function (e) {
if (!root.contains(e.target)) setOpen(false);
});
document.addEventListener("keydown", function (e) {
if (e.key === "Escape") setOpen(false);
});
})();
</script>