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