Simplify setting the options in language selector
This commit is contained in:
@@ -4,10 +4,7 @@
|
||||
<%= t("layouts.header.locale") %>
|
||||
</label>
|
||||
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
||||
<% locales.map do |loc| %>
|
||||
<option lang="<%= loc %>" <%= "selected" if loc == I18n.locale %>
|
||||
value="<%= current_path_with_query_params(locale: loc) %>"><%= name_for_locale(loc) %></option>
|
||||
<% end %>
|
||||
<%= options_for_select(language_options, current_path_with_query_params(locale: I18n.locale)) %>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -10,4 +10,10 @@ class Layout::LocaleSwitcherComponent < ApplicationComponent
|
||||
def locales
|
||||
I18n.available_locales
|
||||
end
|
||||
|
||||
def language_options
|
||||
locales.map do |locale|
|
||||
[name_for_locale(locale), current_path_with_query_params(locale: locale), lang: locale]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user