Extract methods in locale switcher
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
<% if I18n.available_locales.size > 1 %>
|
||||
<div class="locale">
|
||||
<form class="locale-form">
|
||||
<label class="inline-block" for="locale-switcher">
|
||||
<%= t("layouts.header.locale") %>
|
||||
</label>
|
||||
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
||||
<% I18n.available_locales.map do |loc| %>
|
||||
<% locales.map do |loc| %>
|
||||
<option <%= "selected" if loc == I18n.locale %>
|
||||
value="<%= current_path_with_query_params(locale: loc) %>"><%= name_for_locale(loc) %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
||||
delegate :name_for_locale, :current_path_with_query_params, to: :helpers
|
||||
|
||||
def render?
|
||||
locales.size > 1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def locales
|
||||
I18n.available_locales
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user