today_ai_weather/app/views/shared/_language_switcher.html.erb
songtianlun 5f98d9ebfd feat: enhance language switcher dropdown
- Update dropdown to support dynamic locales from I18n
- Limit dropdown height with overflow handling for better UX

This change improves the language switcher by dynamically
loading available locales from the I18n configuration. It
also enhances the user experience by limiting the height
of the dropdown and enabling scrolling, making it easier
to navigate through multiple language options.
2025-02-24 15:55:01 +08:00

17 lines
903 B
Plaintext

<%# app/views/shared/_language_switcher.html.erb %>
<div class="dropdown dropdown-top">
<label tabindex="0" class="btn btn-ghost btn-sm">
<%= t("language.#{I18n.locale}") %>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</label>
<ul tabindex="0" class="dropdown-content menu p-2 max-h-80 overflow-y-auto flex-nowrap shadow bg-base-100 rounded-box w-32">
<% I18n.available_locales.each do |locale| %>
<%= link_to url_for(locale: locale),
class: "px-4 py-2 hover:bg-base-200 rounded-lg #{I18n.locale == locale ? 'bg-base-200' : ''}" do %>
<%= t("language.#{locale}") %>
<% end %>
<% end %>
</ul>
</div>